找回密码
 加入
搜索
查看: 3645|回复: 3

[系统综合] 关于_GetIP()外网IP检测,如果外网不通就卡住了,怎么才可以不通就跳过去

[复制链接]
发表于 2012-4-15 18:12:47 | 显示全部楼层 |阅读模式
关于_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[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)', 2)
    If Not @error Then
        Return ($IP[0])
    Else
        Return SetError(1, 0, 1)
    EndIf
EndFunc
发表于 2012-4-15 18:28:48 | 显示全部楼层
用帮助文件里面自带的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[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) 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[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) Then
                        Return $ip
                EndIf
        EndIf
        Return SetError(1, 0, -1)
EndFunc   ;==>_GetIP
发表于 2012-4-15 19:48:26 | 显示全部楼层
测试通过  没有问题
发表于 2012-4-15 19:57:29 | 显示全部楼层
#include <inet.au3>
 
Do
        Sleep(500)
Until _GetIP()
MsgBox(0,0,_GetIP())
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 16:41 , Processed in 0.083508 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表