Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use BAT batch processing to obtain the IP address of public network

Shulou Source: shulou.com Published: 2022-06-03 16:13:02 11月14日 Update

This article introduces the relevant knowledge of "how to use BAT batch processing to obtain public network IP addresses". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The code is as follows:

:: =

:: IP.bat

:: v0.1

Jinminghou.cn@2009-12-22

:: =

@ echo off

Title GetIP

Set ip=unknown

Echo On Error Resume Next:Set oDOM=WScript.GetObject ("http://www.jinminghou.cn/?app=ip&flag=client&temp="^&now()):Dim i:For I = 1 To 50:If

ODOM.ReadyState= "complete" Then Exit For:End If:WScript.Sleep 200:Next:Dim Temp:Temp=oDOM.documentElement.outerText:Set oDOM=Nothing:Temp=Mid (Temp, Instr

(Temp, "[") + 1, Instr (Temp, "]")-Instr (Temp, "[")-1): WScript.Echo Temp > "% temp%\ GetIP.vbs"

For / f "tokens=1,* delims=:"% I in ('"cscript / / nologo ^"% temp%\ GetIP.vbs ^ "') do set ip=%%i

If exist "% temp%\ Getip.vbs" del "% temp%\ Getip.vbs" > 2 > nul

Echo Your IP: [% ip%]

Pause > 2 > nul

[scheme 1] BAT + VBS

The code is as follows:

@ echo off

Set "URL= http://www.ip138.com/ip2city.asp"

>% temp%/download.vbs echo Set objDOM = WScript.GetObject (WScript.Arguments (0))

> >% temp%/download.vbs echo Do Until objDOM.ReadyState = "complete"

> > temp%/download.vbs echo WScript.Sleep 100

> > temp%/download.vbs echo Loop

> > temp%/download.vbs echo WScript.Echo objDOM.DocumentElement.OuterText

For / f "tokens=2 delims= []" an in ('cscript / / nologo / / e:vbscript% temp%/download.vbs "% URL%"') do (

Set "PublicIP=%%a"

)

Echo,%PublicIP%

Pause

[option 2] BAT + wget.exe (GNU)

The code is as follows:

@ echo off

Set "URL= http://www.ip138.com/ip2city.asp"

For / f "tokens=2 delims= []"% an in ('wget-Q "% URL%"-O -') do (

Set "PublicIP=%%a"

)

Echo,%PublicIP%

Pause

[scheme 3] BAT + curl.exe (GNU)

The code is as follows:

@ echo off

Set "URL= http://www.ip138.com/ip2city.asp"

For / f "tokens=2 delims= []" an in ('curl-s "% URL%"') do (

Set "PublicIP=%%a"

)

Echo,%PublicIP%

Pause

This is the end of the content of "how to use BAT batch processing to obtain the public network IP address". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Code scheme address content more knowledge practicality achievement next dilemma reality situation article case editing website industry process high quality learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Redmi OPPO Reno Apple