以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助] FOX如何获取当前计算机的 IP和计算名?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=34626)

--  作者:eric803
--  发布时间:2013/6/10 12:21:00
--  [求助] FOX如何获取当前计算机的 IP和计算名?
如题, FOX如何获取当前计算机的 IP和计算名?


--  作者:zhl7928
--  发布时间:2013/6/10 13:05:00
--  
http://www.foxtable.com/help/topics/0348.htm    
计算机名
IP不知道额

--  作者:夕然
--  发布时间:2013/6/10 16:04:00
--  

关于ip

猜了一个

 

试试看对不对

IPAddress


--  作者:程兴刚
--  发布时间:2013/6/10 21:09:00
--  

On Error Resume Next
Dim ip,cs As String
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)
            Vars("本机IP") = Replace(.submatches(0) & "|" & .submatches(1), "&nbsp;", "|").split("|")(0)
            Vars("本机城市") = Replace(.submatches(0) & "|" & .submatches(1), "&nbsp;", "|").split("|")(1)
        End With
    End If
End With


--  作者:程兴刚
--  发布时间:2013/6/10 21:10:00
--  
根据论坛的一个帖子改变的本机IP及所属城市代码,我的系统一直这么用!
--  作者:夕然
--  发布时间:2013/6/10 21:45:00
--  
以下是引用程兴刚在2013-6-10 21:09:00的发言:

On Error Resume Next
Dim ip,cs As String
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)
            Vars("本机IP") = Replace(.submatches(0) & "|" & .submatches(1), "&nbsp;", "|").split("|")(0)
            Vars("本机城市") = Replace(.submatches(0) & "|" & .submatches(1), "&nbsp;", "|").split("|")(1)
        End With
    End If
End With

 

 

这个不知道怎么用呢

 

请程老师指点

 

不过,如果要获取本机ip信息还有一个办法,倒是可以获取到。

 

shell("cmd.exe /c ipconfig/all>c:\\ipconfig.txt")
Dim s As String = FileSys.ReadAllText("c:\\ipconfig.txt")
Output.Show(s)

 


--  作者:lxl
--  发布时间:2013/6/10 22:29:00
--  

如果是自己的公网ip的话用程版的就可以。

 

获取本机ip的话,可能获取出多个来,因为可能获取到ipv6 和ipv4等,还有装了多网卡的情况

所以.net提供的方法是根据主机名,获取ip数组

        Dim ipe As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
        For Each ipa As IPAddress In ipe.AddressList
            Output.Show(ipa.AddressFamily.ToString() & ": " & ipa.ToString())
        Next

 

一般路由器上网的话只能获取到内网ip,拨号上网才能获取到公网ip


--  作者:eric803
--  发布时间:2013/6/11 16:01:00
--  
fox没有直接 获取本机IP的函数 吗?


--  作者:狐狸爸爸
--  发布时间:2013/6/13 11:05:00
--  

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=16465&skin=0