怎样获得公网IP
一台电脑,通过路由器上网.有指定IP地址,现在想通过程序获得这台电脑的公网IP,请问要怎么做呢?
作为一个方法来处理这个问题...
Sub Main()
Dim strMachineName As String
'得到主机名
strMachineName = Dns.GetHostName()
Console.WriteLine("Host Name: " + strMachineName)
'通过名字得到主机
Dim ipHost As IPHostEntry
ipHost = Dns.GetHostByName(strMachineName)
'以数组的形式返回相关主机的地址信息
Dim ipAddr() As IPAddress = ipHost.AddressList
Dim count As Integer
'Enumerate the IP Addresses
For count = 0 To ipAddr.GetUpperBound(0)
Console.Write("IP 地址 {0}:{1} ", count, _
ipAddr(count).ToString)
Next
End Sub