关于_GetIP()外网IP检测,如果外网不通就卡住了,怎么才可以不通就跳过去
关于_GetIP()外网IP检测,如果外网不通就卡住了,怎么才可以不通就跳过去If GetIP() = 0 Then
MsgBox(0, "抱歉", "您的广域网不通不能进行验证,请连接外网后继续!")
Exit
Else
EndIf
MsgBox(0, 0, GetIP())
Func GetIP()
$oHTTP = ObjCreate("microsoft.xmlhttp")
$oHTTP.Open("get", "http://city.ip138.com/ip2city.asp", False)
$oHTTP.Send("")
$return = $oHTTP.responsetext;BinaryToString($oHTTP.responseBody)
$IP = StringRegExp($return, '((2\d|25|?\d\d?)\.){3}(2\d|25|?\d\d?)', 2)
If Not @error Then
Return ($IP)
Else
Return SetError(1, 0, 1)
EndIf
EndFunc 用帮助文件里面自带的GetIP 测试没有问题呢,楼主是要验证连网还是要外网IP?
$PublicIP = _GetIP()
If @error Then
MsgBox(0, "提示", "无法获取外网IP")
Else
MsgBox(0, "IP 地址", "您的 IP 地址为: " & $PublicIP)
EndIf
Func _GetIP()
Local $ip, $t_ip
If InetGet("http://checkip.dyndns.org/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
$ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
FileDelete(@TempDir & "\~ip.tmp")
$ip = StringTrimLeft($ip, StringInStr($ip, ":") + 1)
$ip = StringTrimRight($ip, StringLen($ip) - StringInStr($ip, "/") + 2)
$t_ip = StringSplit($ip, '.')
If $t_ip = 4 And StringIsDigit($t_ip) And StringIsDigit($t_ip) And StringIsDigit($t_ip) And StringIsDigit($t_ip) Then
Return $ip
EndIf
EndIf
If InetGet("http://www.whatismyip.com/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
$ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
FileDelete(@TempDir & "\~ip.tmp")
$ip = StringTrimLeft($ip, StringInStr($ip, "Your ip is") + 10)
$ip = StringLeft($ip, StringInStr($ip, " ") - 1)
$ip = StringStripWS($ip, 8)
$t_ip = StringSplit($ip, '.')
If $t_ip = 4 And StringIsDigit($t_ip) And StringIsDigit($t_ip) And StringIsDigit($t_ip) And StringIsDigit($t_ip) Then
Return $ip
EndIf
EndIf
Return SetError(1, 0, -1)
EndFunc ;==>_GetIP
测试通过没有问题 #include <inet.au3>
Do
Sleep(500)
Until _GetIP()
MsgBox(0,0,_GetIP())
页:
[1]