标题: [网络连接] 批处理如何获取自己电脑的外网ip? [打印本页]
作者: 悬崖之树 时间: 2013-7-10 21:58 标题: 批处理如何获取自己电脑的外网ip?
我有个想法,就是用浏览器访问 www.ip138.com,在得到的页面里就可以截取到ip了,但是不知道如何用批处理实现。
作者: Python 时间: 2013-7-10 22:43
http://bbs.bathome.net/thread-2870-1-1.html
http://bbs.bathome.net/thread-4978-1-1.html
作者: 522235677 时间: 2013-7-10 23:46
本帖最后由 pcl_test 于 2017-6-15 19:42 编辑
- @echo off
- more /e +12 %0 >"%temp%\down.vbs"
- wscript //b "%temp%\down.vbs" "http://1212.ip138.com/ic.asp" "%temp%\ip.txt"
- if not errorlevel 99 echo vbs错误 & goto end
- FOR /F "usebackq tokens=2 delims=[]" %%i in ("%temp%\ip.txt") do (if "%%i"=="" (set "ip=ip138.com源码已变更。") else (set ip=%%i))
- for /f "usebackq tokens=2 delims=]" %%a in ("%temp%\ip.txt") do (for /f "delims=<" %%b in ("%%a") do set "ad=%%b")
- echo.%ad% %ip%
- del /q "%temp%\ip.txt"
- :end
- del /q "%temp%\down.vbs"
- pause&exit
-
- With CreateObject("msxml2.Serverxmlhttp")
- .open "get",WScript.Arguments.Item(0),False
- .send
- temp = .responseBody
- End With
- With CreateObject("adodb.stream")
- .Type = 1:.Mode = 3
- .Open()
- .Write(temp)
- .SaveToFile WScript.Arguments.Item(1),2
- .Close
- End With
- Wscript.Quit (99)
复制代码
作者: terse 时间: 2013-7-11 01:03
仅获取外网ip的话 一样用- @echo off
- <"%~f0" more +3 >Getip.vbs
- for /f "tokens=2" %%i in ('cscript //nologo Getip.vbs') do echo 外网%%i&del Getip.vbs&pause&exit
- Set oDOM=WScript.GetObject("http://www.ip.cn/getip.php?action=getip&ip_url=")
- Do Until oDOM.readyState="complete"
- WScript.sleep 100
- Loop
- WScript.echo oDOM.documentElement.outerText
复制代码
作者: PowerShell 时间: 2013-7-11 09:28
powershell 版的在此
http://www.bathome.net/thread-13177-1-2.html
作者: CrLf 时间: 2013-7-11 19:09
非局域网可以直接用 ipconfig,不然可以这样:- @echo off
- down http://iframe.ip138.com/ic.asp ip.txt >nul
- for /f "tokens=2delims=[]" %%a in (ip.txt) do set ip=%%a
- echo 外网ip=%ip%
- pause
复制代码
第三方 down.exe 可以改用 curl 或 wget 或 vbs 脚本什么的
作者: wskwfkbdn 时间: 2013-7-13 23:44
@echo off
curl -o searchip.asp "http://ip.qq.com/">nul 2>nul
for /f "tokens=3 delims=>" %%i in ('type searchip.asp^|find "您当前的IP为"') do set xiao=%%i
echo 您当前的外网IP为:%xiao:~0,-6%
pause
需附带CURL命令行 http://pan.baidu.com/share/link?shareid=2792761129&uk=2164395479
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |