回复 1# wh123wh123
[方案1~5]只返回公网IP,不需要进一步过滤的网址:
https://ifconfig.me/ip
http://ip.42.pl/raw
https://api.ip.sb/ip
[方案6]返回值有其它内容,需要使用正则进行过滤公网IP:
https://ifconfig.me/
http://ip.cn/
http://whatismyip.org
https://ip.sb/
公网IP_1.bat- @echo off
- set "URL=http://ip.42.pl/raw"
- >%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 %%i in ('cscript //nologo "%temp%\download.vbs" "%URL%"') do (
- set "PublicIP=%%i"
- )
- echo,%PublicIP%
- pause
复制代码 公网IP_2.bat
http://bcn.bathome.net/s/tool/index.html?key=wget- @echo off
- set "URL=http://ip.42.pl/raw"
- for /f %%a in ('wget -q "%URL%" -O -') do (
- set "PublicIP=%%a"
- )
- echo,%PublicIP%
- pause
复制代码 公网IP_3.bat
http://bcn.bathome.net/s/tool/index.html?key=curl- @echo off
- set "URL=http://ip.42.pl/raw"
- for /f %%a in ('curl -s "%URL%"') do (
- set "PublicIP=%%a"
- )
- echo,%PublicIP%
- pause
复制代码 公网IP_4.bat- @echo off
- set "url=http://ip.42.pl/raw"
- certutil -urlcache -split -f "%url%" "temp.data" | findstr "0x" || set /p data=<"temp.data"
- echo %data%
- pause
复制代码 公网IP_5-1.bat- @echo off
- powershell "(New-Object System.Net.WebClient).DownLoadString('http://ip.42.pl/raw')"
- pause
复制代码 公网IP_5-2.bat- @echo off
- powershell "(New-Object System.Net.WebClient).DownLoadString('https://ifconfig.me/')"
- pause
复制代码 公网IP_5-3.bat- @echo off
- powershell "(New-Object System.Net.WebClient).DownLoadString('https://api.ip.sb/ip')"
- pause
复制代码 公网IP_5-4.bat- @echo off
- powershell "Invoke-WebRequest -Uri 'https://ifconfig.me/' -UseBasicParsing | ForEach-Object {$_.Content}"
- pause
复制代码 公网IP_6.bat- @echo off
- for /f "delims=:" %%i in ('findstr /n "^:DynamicScript$" "%~f0"') do (
- more +%%i "%~f0" > "%temp%\GetIP.vbs"
- )
- for /f "delims=" %%i in ('cscript //nologo %temp%\GetIP.vbs') do (
- set "PublicIP=%%i"
- )
- echo,%PublicIP%
- pause
- goto :eof
-
- :DynamicScript
- set objDOM = WScript.GetObject("https://ifconfig.me/")
- Do Until objDOM.ReadyState = "complete"
- WScript.Sleep 200
- Loop
- s=objDOM.DocumentElement.InnerText
- set re = New RegExp
- re.Pattern="(\d+)\.(\d+)\.(\d+)\.(\d+)"
- WScript.Echo re.Execute(s)(0)
复制代码 内网IP_1.bat- @echo off
- for /f "tokens=4" %%a in ('route print ^| findstr "0\.0\.0\.0.*0\.0\.0\.0"') do (
- set IP=%%a
- )
- echo %IP%
- pause
复制代码 内网IP_2.bat- @echo off
- for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /c:"IPv4" /c:"IP Address"') do (
- set IP=%%a
- )
- set IP=%IP: =%
- echo %IP%
- pause
复制代码
|