qq724174 发表于 2011-1-30 21:26:31

求助StringRegExp取IP地址

<
MsgBox(0,"",BinaryToString(InetRead("http://www.ip138.com/ip2city.asp",1)))

$oHTTP = InetRead("http://www.ip138.com/ip2city.asp",1)
$s=StringRegExp(BinaryToString($oHTTP),"(?<=<center>).*?(?=</center>)",3)
MsgBox(0,"公网IP获取",$s)
>

以上是通过ip138取出本机外网IP地址的代码
取出结果是“您的IP地址是: ”格式,本人需要“0.0.0.0”这样的格式
通过StringRegExp替换后尝试几种方法总是多了个“[”,代码如下望高手指点。

$b = StringRegExp($s, '(?<=您的IP地址是:).+(?=])',3)
MsgBox(0,0, $b)

风行者 发表于 2011-1-30 23:10:54


#Include <ACN_NET.au3>
MsgBox(32,"外网IP:",BinaryToString(_NetworkGetInternetIP()))

风行者 发表于 2011-1-30 23:23:35

$Url = "http://www.ip138.com/ip2city.asp"
$Sre = StringRegExp(BinaryToString(InetRead($Url,1)),'\[(.+)]',3)
MsgBox(32,"外网IP:",$Sre)

lpxx 发表于 2011-1-30 23:29:59

实在不行变通一下
MsgBox(0,"",BinaryToString(InetRead("http://www.ip138.com/ip2city.asp",1)))
$oHTTP = InetRead("http://www.ip138.com/ip2city.asp",1)
$s=StringRegExp(BinaryToString($oHTTP),"\[(.*?)\]",3)
MsgBox(0,"公网IP获取","您的IP地址是:"&$s)

qq724174 发表于 2011-1-31 00:15:25

回复 3# 风行者


多谢风行者 测试你的代码可以用 而且比我开始的简单的多了 谢谢你。
页: [1]
查看完整版本: 求助StringRegExp取IP地址