Paulio

Hi, ive been looking all over microsoft and the internet for this solution without any success. Hopefully somebody can help.

All I want to do is grab the IP details of the local machine in VB 2008 (or previous versions) using actual coding and not relying on output from ipconfig/all. I specifically need the subnet mask and gateway of the local machine.

I have found documents on how to do this in C++ using the networkadapter functions which is of no use to me because im using VB. Ive managed to find how to get the local ip address (using winsock or third party control) but nothing more and a few pages on using WMI but all examples are using vbscript rather than the full blown visual basic.

Does anybody know how to do this in vb and have any sample code

As a network server administrator im confused on why this is so difficult, even in VB.

Thanks

Paulio



Re: Visual Basic Language Get local Ip Details with VB 2008/2005?

jo0ls

Look in the System.Net.NetworkInformation namespace.

Loop through the adapters with a for..each loop:

For Each ni As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()

Some properties are directly available from the network interface - name and mac address (physical address).

Some are deeper. To get the gateway info for an adapter:

For Each gip As GatewayIPAddressInformation In ni.GetIPProperties().GatewayAddresses

Here gip will have an address property for the gateway address.

To get IPV4 info, loop through the UnicastAddresses that the network interface has:

For Each uiai As UnicastIPAddressInformation In ni.GetIPProperties.UnicastAddresses

Here you can get the IP address and IPV4Mask.




Re: Visual Basic Language Get local Ip Details with VB 2008/2005?

Paulio

Thanks a lot for this, much appreciated. I will look into this namespace.

Paulio





Re: Visual Basic Language Get local Ip Details with VB 2008/2005?

rkimble

Hi Paulio,

Jo0ls has you on the correct track. You may also want to see this thread for more information.