1
A
回答
0
Dim myClientMachineAddressList As IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName())
Dim myClientMachineIP As String = myClientMachineAddressList.AddressList(0).ToString()
編輯:
那麼你可以使用IPAddress.AddressFamily找出IP familly類型。
4
像這樣的事情
Public Function GetIpV4() As String
Dim myHost As String = Dns.GetHostName
Dim ipEntry As IPHostEntry = Dns.GetHostEntry(myHost)
Dim ip As String = ""
For Each tmpIpAddress As IPAddress In ipEntry.AddressList
If tmpIpAddress.AddressFamily = Sockets.AddressFamily.InterNetwork Then
Dim ipAddress As String = tmpIpAddress.ToString
ip = ipAddress
exit for
End If
Next
If ip = "" Then
Throw New Exception("No 10. IP found!")
End If
Return ip
End Function
+0
+1寫得不錯:) – Cicik 2010-05-25 21:30:30
1
盡我所能做到的是,將只使用陣列功能和lambda表達式,很乾淨僅返回IPv4地址 :
Public Function GetHostEntryIPv4(ByVal addr As String) As IPHostEntry
Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(addr)
If Not IsNothing(ipHostInfo) Then
ipHostInfo.AddressList = Array.FindAll(ipHostInfo.AddressList, Function(n As IPAddress) n.AddressFamily = AddressFamily.InterNetwork)
End If
GetHostEntryIPv4 = ipHostInfo
End Function
相關問題
- 1. 力InetAddress.getHostAddress()返回IPv4地址
- 2. remote_addr不返回IPv4地址
- 3. 的Java getHostAddress()返回VirtualBox的IPv4地址
- 4. 如何使用VB.net顯示IPv4地址
- 5. 多個IPV4地址
- 6. 編碼IPv4地址
- 7. IPv4地址替換
- 8. 使用VBScript將ipv4地址作爲變量返回
- 9. 如何將IPv4地址轉換爲整數並返回C?
- 10. 爲什麼UnicastIPAddressInformation.IPv4Mask在IPv4地址上返回空值?
- 11. Java DatagramPacket對象返回IPV6地址,但要求IPv4
- 12. Pinging win2k16返回的是IPv6地址而不是IPv4
- 13. Inet6Address.getByName()是否返回(現有)IPv6,但只有IPv4地址?
- 14. gethostbyname是否保證返回帶有IPv4地址的hostent結構?
- 15. 在Android上從IPv4地址合成IPv4映射的IPv6地址?
- 16. 如何從IPv4映射的IPv6地址解析IPv4地址?
- 17. 在bat-file中只獲取沒有「IPv4地址......」的IPv4地址
- 18. 返回地址
- 19. Patricia/radix樹和ipv4地址
- 20. 淨ip地址的IPv4
- 21. IPv4地址自動更改
- 22. Tarantool 1.6不聽ipv4地址
- 23. Java獲取IPv4地址
- 24. 如何匹配IPv4地址
- 25. inet_aton IPv4地址規範化
- 26. 檢查字符串是否包含VB.Net中的IPv4地址
- 27. 返回地址C
- 28. Python:socket.recvfrom()返回地址
- 29. GetHostAddress()不返回IPv6,僅返回IPv4
- 30. getaddrinfo()返回回送地址
你想要的IP地址給定主機名?或傳入請求的IP地址?或本地計算機的IP地址(可能有多個地址)? – Jason 2010-05-25 21:31:10