标题: [网络连接] 批处理如何获取本机公网ip/外网ip? [打印本页]
作者: winsfly 时间: 2013-4-9 12:50 标题: 批处理如何获取本机公网ip/外网ip?
本帖最后由 pcl_test 于 2016-9-5 03:44 编辑
如题,在网吧的话,可以打开ip138.com查看网吧使用的公有地址,用批处理怎么做到呢?还有如果是家里的adsl宽带又怎么做呢?
作者: 522235677 时间: 2013-4-9 14:40
本帖最后由 pcl_test 于 2016-9-4 19:51 编辑
- @echo off
- more /e +10 %0 >"%temp%\down.vbs"
- wscript //b "%temp%\down.vbs" "http://1212.ip138.com/ic.asp" "%temp%\ip.txt"
- if not "%errorlevel%"=="99" (echo error)
- FOR /F "usebackq tokens=2 delims=[]" %%i in ("%temp%\ip.txt") do set ip=%%i
- if "%ip%"=="" (set "ip=ip138.com源码已变更。")
- 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%
- 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)
复制代码
作者: winsfly 时间: 2013-4-9 15:44
回复 2# 522235677
没有结果啊,只有ip138.com源码已变更
作者: yu2n 时间: 2013-4-9 16:50
本帖最后由 pcl_test 于 2016-9-4 19:52 编辑
522235677 发表于 2013-4-9 14:40
照搬代码,试试。- @echo off
- more /e +10 %0 >"%temp%\down.vbs"
- wscript //b "%temp%\down.vbs" "http://1212.ip138.com/ic.asp" "%temp%\ip.txt"
- FOR /F "usebackq tokens=2 delims=[]" %%i in ("%temp%\ip.txt") do set ip=%%i
- if "%ip%"=="" (set "ip=ip138.com源码已变更。")
- 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:%ip%
- pause&exit
-
-
-
- Call DownloadFile(WScript.Arguments.Item(0), WScript.Arguments.Item(1))
- Function DownloadFile(URL,SavePath)
- On Error Resume Next
- Dim fso, xPost
- Set fso= Wscript.Createobject("Scripting.FileSystemObject")
- Set xPost = createObject("Microsoft.XMLHTTP")
- xPost.Open "GET",URL,0 ''''下载文件的地址
- xPost.Send()
- Set sGet = CreateObject("ADODB.Stream")
- sGet.Mode = 3
- sGet.Type = 1
- sGet.Open()
- sGet.Write(xPost.responseBody)
- sGet.SaveToFile SavePath,2 ''''保存文件的路径和文件名
- if (fso.FileExists(SavePath)) Then '检测文件是否存在
- DownloadFile = True
- else
- DownloadFile = False
- end if
- set fso=Nothing
- End Function
复制代码
简体XP 32位执行结果如下:- 来自:广东省东莞市 电信 IP:183.22.169.214
- 请按任意键继续. . .
复制代码
作者: chinastar2009 时间: 2013-4-9 16:54
http://www.ip138.com/ips1388.asp
138查询地址变更为这个
作者: terse 时间: 2013-4-9 17:09
本帖最后由 pcl_test 于 2016-9-4 20:04 编辑
本机外网- @echo off
- <"%~f0" more +3 >Getip.vbs
- cscript //nologo Getip.vbs&del Getip.vbs&pause&exit
- Set oDOM=WScript.GetObject("http://1212.ip138.com/ic.asp")
- Do Until oDOM.readyState="complete"
- WScript.sleep 100
- Loop
- WScript.echo oDOM.documentElement.outerText
复制代码
查询版的- @echo off
- set/p uip=请输入要查询的IP:
- IF "%uip%" equ "" (set dip=getip)else set "dip=queryip"
- (echo Set oDOM=WScript.GetObject("http://www.ip.cn/getip.php?action=%dip%&ip_url=%uip%"^)
- echo Do Until oDOM.readyState="complete"
- echo WScript.sleep 100
- echo Loop
- echo WScript.echo oDOM.documentElement.outerText)>Getip.vbs
- for /f "delims=" %%i in ('cscript //nologo Getip.vbs') do echo %%i&del Getip.vbs&pause&exit
复制代码
作者: winsfly 时间: 2013-4-28 11:37
回复 6# terse
十分感谢
作者: pcl_test 时间: 2016-9-4 20:48
本帖最后由 pcl_test 于 2016-9-4 20:49 编辑
6楼查询网址已失效,更新下- @echo off
- set/p ip=请输入要查询的IP并按回车键(直接按回车键为查询本机公网IP):
- if "%ip%" neq "" set "str=?ip=%ip%"
- (
- echo;Set ie=CreateObject("InternetExplorer.Application"^)
- echo;ie.Visible=false
- echo;ie.navigate "http://www.ip.cn/index.php%str%"
- echo;Do
- echo;WSH.Sleep 500
- echo;Loop Until ie.readyState=4
- echo;WSH.echo replace(ie.Document.getElementByID("result"^).innertext,vbCrLf," "^)
- echo;ie.quit
- )>"%temp%\Getip.vbs"
- for /f "delims=" %%i in ('cscript //nologo "%temp%\Getip.vbs"') do echo;%%i&del "%temp%\Getip.vbs"&pause&exit
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |