#Region
#PRE_Icon=ip.ico
#PRE_Outfile=获取外网IP.exe
#PRE_UseX64=n
#PRE_Res_Description=i@smallan.net
#PRE_Res_Fileversion=1.0.0.2
#PRE_Res_LegalCopyright=i@smallan.net
#PRE_Res_requestedExecutionLevel=None
#EndRegion
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("外网IP获取", 286, 138, -1, -1)
$Label1 = GUICtrlCreateLabel("外网IP", 32, 20, 38, 17)
$Input1 = GUICtrlCreateInput("获取中请稍后……", 88, 16, 161, 21, $SS_CENTER)
$Label2 = GUICtrlCreateLabel("IP信息", 32, 56, 38, 17)
$Label3 = GUICtrlCreateLabel("获取中请稍后……", 88, 56, 156, 17, $SS_CENTER)
$Button1 = GUICtrlCreateButton("线路 01 ", 15, 96, 75, 25)
$Button2 = GUICtrlCreateButton("线路 02 ", 105, 96, 75, 25)
$Button3 = GUICtrlCreateButton("清空数据", 195, 96, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_GetIpNet()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_GetIpNet()
Case $Button2
_GetUUIp()
Case $Button3
GUICtrlSetData($Input1, "")
GUICtrlSetData($Label3, "")
EndSwitch
WEnd
Func _GetIpNet()
$sGetIPNetInfo = BinaryToString(InetRead("http://myip.ipip.net", 8), 4)
If $sGetIPNetInfo = Null Then
GUICtrlSetData($Input1, "获取失败,请更新版本")
EndIf
$sHandleIpInfo = StringSplit($sGetIPNetInfo, ' ')
$sIpAdd = StringSplit($sHandleIpInfo[2], ':')
GUICtrlSetData($Input1, $sIpAdd[2])
GUICtrlSetData($Label3, $sHandleIpInfo[5] & " " & $sHandleIpInfo[6] & " " & $sHandleIpInfo[8])
EndFunc
Func _GetUUIp()
$sGetUUNetInfo = BinaryToString(InetRead("https://ie.uu.163.com/ip", 8), 4)
If $sGetUUNetInfo = Null Then
GUICtrlSetData($Input1, "获取失败,请更新版本")
EndIf
$sUUIpAdd = _JsonRead($sGetUUNetInfo, 'data.ip')
$sUUArea = _JsonRead($sGetUUNetInfo, 'data.country') & " " & _JsonRead($sGetUUNetInfo, 'data.region') & " " & _JsonRead($sGetUUNetInfo, 'data.isp')
GUICtrlSetData($Input1, $sUUIpAdd)
GUICtrlSetData($Label3, $sUUArea)
EndFunc
Func _JsonRead($sJson = "", $sMember = '')
Local $sResult, $sCode = ""
$sJson = StringRegExpReplace ($sJson, '[\r\n]+', '');去除换行
$sCode &= 'function json2str()' & @CRLF
$sCode &= '{' & @CRLF
$sCode &= "var jsontext = '" & $sJson & "';" & @CRLF
$sCode &= 'var obj = eval("("+jsontext+")");' & @CRLF ; json2object
$sCode &= 'var member = obj.' & $sMember & @CRLF ;取出信息
$sCode &= 'return member' & @CRLF
$sCode &= '}' & @CRLF
Local $oScript = ObjCreate("MSScriptControl.ScriptControl.1")
$oScript.language = 'JavaScript'
$oScript.AddCode($sCode)
$sResult = $oScript.Run('json2str')
$oScript = 0
Return $sResult
EndFunc ;This fn from autoitx.com bbs
其实两种都是对String的处理,只不过更多的会是对JSON格式返回值的处理,仅供查看