IP Address Lookup in VB.net (XP vs Windows 7)

Posted by TheHockeyGeek on Stack Overflow See other posts from Stack Overflow or by TheHockeyGeek
Published on 2010-03-30T14:59:48Z Indexed on 2010/03/30 15:03 UTC
Read the original article Hit count: 592

Currently I use the following code to retrieve the IP address of the local workstation...

strIPAddress = System.Net.Dns.GetHostEntry(strComputerName).AddressList(0).ToString()

This is fine for the Windows XP workstations. However, in Vista and Windows 7, this returns the IPv6 address which is not used at all. Is there a method of setting this to work so it always returns the IPv4 address regardless of platform?

I know I can increment the AddressList value to 1 and get the correct IP in Windows 7. The bad part is that this requires going through the motions of identifying the OS and choosing one or the other.

The must be some way of specifying IPv4 only. Perhaps getting a result from DNS on the network rather than the workstation itself?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about ip-address