In the foreach loop, you can check the AddressFamily property of each address and return the first IPv4 one found. On my system, that's actually the third one in the list.
Hier die konvertierte Variante:
VB.NET-Quellcode
PrivateSharedFunction GetIP() As IPAddress
Dim thisIp As IPAddress =Nothing
Dim strHostName AsString= Dns.GetHostName()
Dim iphostentry As IPHostEntry = Dns.GetHostEntry(strHostName)
' Find host name
ForEach ipAddress As IPAddress In iphostentry.AddressList
' Grab the first IP addresses
If ipAddress.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
die Lösung von nikeee13 ist Perfekt... mit If ipAddress.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
wird überprüft ob es eine IP der Version 4 ist und genau das ist die Vorraussetzung für das funktionieren(es sei denn man baut IPv6 Support ein...) in Vista+ wird die IPv6 ausgegeben...
Ich wollte auch mal ne total überflüssige Signatur:
---Leer---
Gutelaunetyp,
dein Prüfen auf das OS ist ja grauenhaft!
mach es so: