VBS 调用 Msxml2.ServerXMLHTTP 获取网页上的地址信息 | | | Msgbox "外网IP为:" & getIP() | | | | Function getIP() | | Dim strHtml, strIP | | If strIP = "" Then | | strHtml = HttpGet("http://yu2n.sinaapp.com/app/f/ip/AddIP.php?ip=show_client") | | strIP = Join(regEx_execute("\d+\.\d+\.\d+\.\d+", strHtml)) | | End If | | If strIP = "" Then | | strHtml = HttpGet("http://iframe.ip138.com/ic.asp") | | strIP = Join(regEx_execute("\d+\.\d+\.\d+\.\d+", strHtml)) | | End If | | If strIP = "" Then | | strHtml = HttpGet("http://www.whereismyip.com/") | | strIP = Join(regEx_execute("\d+\.\d+\.\d+\.\d+", strHtml)) | | End If | | getIP = strIP | | End Function | | | | Function HttpGet(ByVal url) | | With CreateObject("Msxml2.ServerXMLHTTP") | | .open "GET", url, False | | .send | | HttpGet = .responseText | | End With | | End Function | | | | | | | | | | | | | | Function regEx_execute(ByVal sPattern, ByVal str) | | Dim regEx, Match, Matches, arrMatchs(), i : i = -1 | | Set regEx = CreateObject("VBScript.RegExp") | | regEx.Pattern = sPattern | | regEx.IgnoreCase = True | | regEx.Global = True | | regEx.MultiLine = True | | Set Matches = regEx.Execute(str) | | For Each Match in Matches | | If Not Match.Value = "" Then | | i = i + 1 | | ReDim Preserve arrMatchs(i) | | arrMatchs(i) = Match.Value | | End If | | Next | | regEx_execute = arrMatchs | | Set Match = Nothing | | Set regEx = Nothing | | End FunctionCOPY |
|