How to get the IP address of the current host?
-
Hi gurus, I'd like to know how to get the IPv4 address of the current host in .NET 2? Thanks. Best regards. Fred. There is no spoon.
it is like ipv6= 0.0.ipv4 Mikail Çetinkaya . The C# DEveloper
-
Hi gurus, I'd like to know how to get the IPv4 address of the current host in .NET 2? Thanks. Best regards. Fred. There is no spoon.
You could get the host name from the DNS.GetHostName[^] method, then pass that name to the Dns.GetHostAddresses[^] method to retrieve all the IP addresses known for this host. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
it is like ipv6= 0.0.ipv4 Mikail Çetinkaya . The C# DEveloper
:wtf: :confused: Whatever that means... and no, that's not how an IP6 address looks. You didn't even tell him how to resolve the name, let alone find the name of the machine. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You could get the host name from the DNS.GetHostName[^] method, then pass that name to the Dns.GetHostAddresses[^] method to retrieve all the IP addresses known for this host. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
yes, I know, this is shown in the msdn, but how to get the right address? That is the one which appears in the properties pannel of the network connection... fred. There is no spoon.
There is no "right-address". A single NIC can have multiple addresses assigned to it. This is the address that DNS servers know about. You could also get this from WMI (System.Management namespace). All you need to do is search for all the occurances of Win32_NetworkAdapterConfiguration objects. Each will have its own array of IPAddresses. Warning: You might be surprised at how many of these object and addresses there really are! Once you have those, examine them to see which ones have an active DefaultIPGateway. This will be the adapter and set of addresses that your talking about. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome