Foxtable(狐表)用户栏目专家坐堂 → 如何获取本机的IP地址


  共有10584人关注过本帖树形打印复制链接

主题:如何获取本机的IP地址

帅哥哟,离线,有人找我吗?
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:732 积分:5491 威望:0 精华:14 注册:2011/8/28 12:49:00
  发帖心情 Post By:2012/10/12 9:03:00 [显示全部帖子]

Dim HostName As String = System.Net.Dns.GetHostName
Dim LocalIPAddress As System.Net.IPAddress = System.Net.Dns.GetHostByName(HostName).AddressList.GetValue(0)

Msgbox(LocalIPAddress)


 回到顶部
帅哥哟,离线,有人找我吗?
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:732 积分:5491 威望:0 精华:14 注册:2011/8/28 12:49:00
  发帖心情 Post By:2012/10/12 17:37:00 [显示全部帖子]

'我用的疼迅的网页,同时获取IP与归属地,返回值格式为:IP|归属地

 

On Error Resume Next
Dim httpURL As New System.Uri("http://ip.qq.com/")
Dim httpReq As System.Net.HttpWebRequest = System.Net.WebRequest.Create(httpURL)
httpReq.Method = "GET"
Dim httpResp As System.Net.HttpWebResponse = httpReq.GetResponse()
httpReq.KeepAlive = False
Dim reader As New IO.StreamReader(httpResp.GetResponseStream, System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd()

With CreateObject("vbscript.regexp")
    .Global = True
    .MultiLine = True
    .ignorecase = True
    .Pattern = "当前的IP为.*?\<.*?\>([^<>]+)[\s\S]*?IP所在地为.*?\<.*?\>([^<>]+)"
    If .test(respHTML) Then
        With .Execute(respHTML)(0)
            Return Replace(.submatches(0) & "|" & .submatches(1), "&nbsp;", " ")
        End With
    End If
End With
Return


 回到顶部