以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  怎样通过命令获取用户端当前的IP地址?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=89536)

--  作者:大红袍
--  发布时间:2016/8/23 23:43:00
--  

内外ip

 

Dim IPAdress As System.Net.IPAddress
Dim HostName As String
HostName = System.Net.Dns.GetHostName \'获得本机的机器名
Dim l As Integer = System.Net.Dns.GetHostByName(HostName).AddressList.Length
For i As Integer=0 To l-1
  IPAdress = System.Net.Dns.GetHostByName(HostName).AddressList.getValue(i) \'获得本机的IP
  output.show(IPAdress.Tostring)
Next

 

外网ip

 

Dim WinHttpReq As Object = CreateObject("Msxml2.ServerXMLHTTP")
WinHttpReq.Open("GET", "http://1212.ip138.com/ic.asp")
WinHttpReq.Send
\'正则表达式解析出外网IP
Dim str As String = WinHttpReq.ResponseText
Dim mc = System.Text.RegularExpressions.Regex.Matches(str, "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+")
If mc.count > 0 Then
    msgbox(mc(0).value)
End If