Board logo

标题: 讨论 完善新的外网IP获取 [打印本页]

作者: hackiller     时间: 2008-1-7 11:00    标题: 讨论 完善新的外网IP获取

原来那个外网IP获取是通过swz8.com网站提取的 现在这网站已经关了 小弟从ip138找到了它的IP获取页面 但文字处理上 俺不大会 请帮忙完善 @echo off title 获取本机内网和外网IP if exist ip2city.asp del ip2city.asp if exist ip.txt del ip.txt if exist 1.txt del 1.txt if exist 2.txt del 2.txt wget http://www.ip138.com/ip2city.asp ren ip2city.asp 1.txt 此时1.txt内容为
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title> 您的IP地址 </title>
</head>
<body style="margin:0px"><center>您的IP地址是:[1.1.1.1] 来自:湖南省株洲市 电信</center></body></html>
以下再用SED提取 sed -r "s/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\n\1/;s/^.*\n//" 1.txt >2.txt for /f %%i in (2.txt) do set i=%%i echo %i% >ip.txt start ip.txt IP.txt内容为
1.1.1.1空格接回车
我是新手 请高手帮忙精简完善 去掉IP.TXT的空格接回车

作者: hackiller     时间: 2008-1-7 11:03
很多去空格和回车的代码 我试了 没效果

作者: junchen2     时间: 2008-1-7 11:18
sed "s/[ |\t]\+$//" ip.txt

作者: hackiller     时间: 2008-1-7 11:21
Originally posted by junchen2 at 2008-1-7 11:18 AM: sed "s/[ |\t]\+$//" ip.txt
sed "s/[ |\t]\+$//" ip.txt >1.txt 空格变成了黑块 回车还是回车

作者: hackiller     时间: 2008-1-7 11:33
在网上找到一个VBS的 但结果也不是纯数字
set http=createobject("Microsoft.XMLHTTP")
ipp="http://www.ip138.com/ip2city.asp"
http.open "get",ipp,false
http.send
ss=bytes2BSTR(Http.responsebody)
ss=Replace(ss,vbcrlf,"")
Set re = New RegExp
re.Pattern = "(.+valign=""top"">)(.+\d+\.\d+\.\d+\.\d+)(.+)"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$2")
msgbox rv
Function bytes2BSTR(vIn)
     strReturn = ""
     For i = 1 To LenB(vIn)
         ThisCharCode = AscB(MidB(vIn,i,1))
         If ThisCharCode < &H80 Then
             strReturn = strReturn & Chr(ThisCharCode)
         Else
             NextCharCode = AscB(MidB(vIn,i+1,1))
             strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
             i = i + 1
         End If
     Next
     bytes2BSTR = strReturn
End Function

作者: lxmxn     时间: 2008-1-7 12:44
for /f "delims=[] tokens=2" %a in ('wget -qO- http://www.ip138.com/ip2city.asp^|findstr /rc:"\[[0-9.]*\]"') do @set/p=my ip is [%a]<nul>1.txt

作者: zh159     时间: 2008-1-7 13:44
用VBS获取:
@echo off
echo 正在连接,请稍等...
>Getip.vbs echo Set oDOM=WScript.GetObject("http://www.ip138.com/ip2city.asp"):Do Until oDOM.readyState="complete":WScript.sleep 200:Loop:WScript.echo oDOM.documentElement.outerText:Set oDOM=nothing
for /f "tokens=2 delims=[]" %%i in ('"cscript //nologo Getip.vbs"') do echo 你的外网 IP 是: %%i
del Getip.vbs
pause
VBS部分就是(一定要有WScript.sleep 200延时部分,否则会占用99%系统资源及长时间得不出数据):
Set oDOM=WScript.GetObject("http://www.ip138.com/ip2city.asp")
Do Until oDOM.readyState="complete"
WScript.sleep 200
Loop
WScript.echo oDOM.documentElement.outerText
Set oDOM=nothing
[ Last edited by zh159 on 2008-1-7 at 01:49 PM ]

作者: yagu1648     时间: 2008-8-29 23:30
for /f "skip=6 delims=[] tokens=2" %%a in ('wget -qO- www.ip138.com/ip2city.asp') do set IP=%%a&echo %IP:~0,-2%>IP.txt 回车不好去。。。

作者: pighead123     时间: 2008-12-8 19:06
for /f "delims=[] tokens=2" %%a in ('wget -qO- http://www.ip138.com/ip2city.asp^|findstr /rc:"\[[0-9.]*\]"') do @set/p=%%a<nul>1.txt
纯数字 版主那个已经给出答案了 [ Last edited by pighead123 on 2008-12-8 at 19:16 ]

作者: ily2013     时间: 2008-12-9 15:19
我的是这样的 curl members.3322.org ... 以前也是在ip138获取,不过分析ip出来麻烦了点