怎样得到自己的IP地址
在vb.net中怎么得到自己的IP,谢谢 --------------------编程问答-------------------- Private Function GetIPAddress() As StringDim strIPAddress As String
Try
strIPAddress = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList(0).ToString
Catch ex As Exception
Return String.Empty
End Try
Return strIPAddress
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(GetIPAddress)
我用了这代码,为什么返回的是“fe80::3c44:d60:3f57:fefd&10”
End Sub --------------------编程问答-------------------- System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName).HostName.ToString() --------------------编程问答-------------------- 提示System.Net.Dns.GetHostByName 已过期 --------------------编程问答-------------------- Dns.GetHostEntry(Dns.GetHostName()).AddressList --------------------编程问答-------------------- 还是不太懂,楼上的又提示dns没有定义,谁能直接告诉我怎样得到strip
textbox1.text=strip --------------------编程问答-------------------- Dim strHostName As String
Dim strIPAddress As String
strHostName = System.Net.Dns.GetHostName()
strIPAddress = System.Net.Dns.Resolve(strHostName).AddressList(0).ToString()
MessageBox.Show("Host Name: " & strHostName & "; IP Address: " & strIPAddress)
这样既获得了机器的机器名和IP --------------------编程问答-------------------- Dim strIp as string = Request.Url.ToString --------------------编程问答-------------------- System.Net.Dns.Resolve(strHostName).
说这个过期 --------------------编程问答-------------------- 未声明Request --------------------编程问答-------------------- Dim IPAdress As System.Net.IPAddress = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName).AddressList.GetValue(0)
MsgBox(IPAdress.ToString)
试试这个呢,我可以得到了. --------------------编程问答-------------------- 留名帮顶 --------------------编程问答-------------------- System.Net.Dns.GetHostByName这个没有声明 --------------------编程问答-------------------- 标记 --------------------编程问答-------------------- Imports System.Net
Imports System.Net.Sockets
Dns.GetHostEntry(Dns.GetHostName()).AddressList(0).ToString --------------------编程问答--------------------
LZ你把包都引一下.. --------------------编程问答-------------------- 外网的IP地址比较麻烦,需要通过访问个网站,然后取出这个网站显示的自己的IP地址就是外网地址,直接取很多情况下的取到的都是不正确的 --------------------编程问答-------------------- CMD 里PING 一下 --------------------编程问答--------------------
如果要取外网的IP,这个正解..用2个基本的dos命令,就可以搞定.又准...
--------------------编程问答-------------------- System.Net.Dns.GetHostEntry(My.Computer.Name).AddressList(0).ToString
补充:.NET技术 , VB.NET