|
hackiller
初级用户
 
积分 39
发帖 16
注册 2006-12-16
状态 离线
|
『楼 主』:
讨论 完善新的外网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内容为 我是新手 请高手帮忙精简完善 去掉IP.TXT的空格接回车
|
|
2008-1-7 11:00 |
|
|
hackiller
初级用户
 
积分 39
发帖 16
注册 2006-12-16
状态 离线
|
『第
2 楼』:
很多去空格和回车的代码 我试了 没效果
|
|
2008-1-7 11:03 |
|
|
junchen2
高级用户
   
积分 537
发帖 219
注册 2007-8-4 来自 杭州--半山
状态 离线
|
『第
3 楼』:
sed "s/[ |\t]\+$//" ip.txt
|
|
2008-1-7 11:18 |
|
|
hackiller
初级用户
 
积分 39
发帖 16
注册 2006-12-16
状态 离线
|
『第
4 楼』:
Originally posted by junchen2 at 2008-1-7 11:18 AM:
sed "s/[ |\t]\+$//" ip.txt sed "s/[ |\t]\+$//" ip.txt >1.txt
空格变成了黑块 回车还是回车
|
|
2008-1-7 11:21 |
|
|
hackiller
初级用户
 
积分 39
发帖 16
注册 2006-12-16
状态 离线
|
『第
5 楼』:
在网上找到一个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
|
|
2008-1-7 11:33 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第
6 楼』:
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
|
|
2008-1-7 12:44 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第
7 楼』:
用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 ]
|

|
|
2008-1-7 13:44 |
|
|
yagu1648
新手上路

积分 2
发帖 1
注册 2006-12-18
状态 离线
|
『第
8 楼』:
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
回车不好去。。。
|
|
2008-8-29 23:30 |
|
|
pighead123
初级用户
 
积分 42
发帖 23
注册 2006-2-13
状态 离线
|
『第
9 楼』:
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 ]
|

|
|
2008-12-8 19:06 |
|
|
ily2013
中级用户
  
积分 247
发帖 83
注册 2005-9-12
状态 离线
|
|
2008-12-9 15:19 |
|