[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
VBS 调用 Msxml2.ServerXMLHTTP 获取网页上的地址信息
  1. ' getIP.vbs
  2. Msgbox "外网IP为:" & getIP()
  3. Function getIP()
  4.     Dim strHtml, strIP
  5.     If strIP = "" Then
  6.         strHtml = HttpGet("http://yu2n.sinaapp.com/app/f/ip/AddIP.php?ip=show_client")
  7.         strIP = Join(regEx_execute("\d+\.\d+\.\d+\.\d+", strHtml))
  8.     End If
  9.     If strIP = "" Then
  10.         strHtml = HttpGet("http://iframe.ip138.com/ic.asp")
  11.         strIP = Join(regEx_execute("\d+\.\d+\.\d+\.\d+", strHtml))
  12.     End If
  13.     If strIP = "" Then
  14.         strHtml = HttpGet("http://www.whereismyip.com/")
  15.         strIP = Join(regEx_execute("\d+\.\d+\.\d+\.\d+", strHtml))
  16.     End If
  17.     getIP = strIP
  18. End Function
  19. Function HttpGet(ByVal url)
  20.     With CreateObject("Msxml2.ServerXMLHTTP")
  21.         .open "GET", url, False
  22.         .send
  23.         HttpGet = .responseText
  24.     End With
  25. End Function
  26. ' ====================================================================================================
  27. ' 检查字符串是否符合正则表达式
  28. 'Msgbox Join(regEx_execute( "[A-z]", "a-v d-f b-c"), " | ")
  29. 'Msgbox regEx_replace( "[A-z]+-[A-z]+", "a-v d-f b-c", " | ")
  30. ' 取得正则表达式搜索结果,返回数组
  31. Function regEx_execute(ByVal sPattern, ByVal str)
  32.     Dim regEx, Match, Matches, arrMatchs(), i : i = -1    ' 建立变量。
  33.     Set regEx = CreateObject("VBScript.RegExp") ' 建立正则表达式。
  34.         regEx.Pattern = sPattern      ' 设置模式。
  35.         regEx.IgnoreCase = True    ' 设置是否区分字符大小写。
  36.         regEx.Global = True        ' 设置全局可用性。
  37.         regEx.MultiLine = True     ' 多行匹配模式
  38.     Set Matches = regEx.Execute(str)      ' 执行搜索。
  39.     For Each Match in Matches  ' 遍历匹配集合。
  40.         If Not Match.Value = "" Then
  41.             i = i + 1
  42.             ReDim Preserve arrMatchs(i) ' 动态数组:数组随循环而变化
  43.             arrMatchs(i) = Match.Value
  44.         End If
  45.     Next
  46.     regEx_execute = arrMatchs
  47. Set Match = Nothing
  48. Set regEx = Nothing
  49. End Function
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

返回列表