Get ip address and network info vb.net

CraigLazar
CraigLazar used Ask the Experts™
on
Hi,
I have written a small app in vb.net 08 and i need to somehow fetch the IP address(s) plus, subnet mask, default gateway and DNS server info if possible from a machine

thanks allot

cheers
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Project manager
Commented:
Create a new project and add a reference to System.Management.dll, paste this code in a button click or similar
Dim mc As New Management.ManagementClass("Win32_NetworkAdapterConfiguration")        
Dim nics As Management.ManagementObjectCollection        
nics = mc.GetInstances()        
Dim nic As Management.ManagementObject        
For Each nic In nics
            If nic("ipEnabled") = True Then
                Dim s As String
                MessageBox.Show(nic("IPAddress"))
                For Each s In nic("IPSubnet")
                    MessageBox.Show(s, nic("Caption"))
                Next            
             End If        
Next

Open in new window

Dirk HaestProject manager

Commented:
For Each f As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
    If f.OperationalStatus = OperationalStatus.Up Then
        For Each d As GatewayIPAddressInformation In f.GetIPProperties().GatewayAddresses
            MessageBox.Show(d.Address.ToString())
        Next
    End If
Next

Author

Commented:
Hi Dhaest,
Thanks for the code,
i got ur first post working, but i checked on MSDN and see that using Win32_NetworkAdapterConfiguration, there is no property to indicate wheather the ip is connected or not.
I need to report all the netwrok adapters with there information and if they are connected or not

is that possible?

thanks
Dirk HaestProject manager

Commented:
>> I need to report all the netwrok adapters with there information and if they are connected or not

That's another question than the original question where you asked for the  address(s) plus, subnet mask, default gateway and DNS server info if possible from a machine

I'm not sure if you can see this !

Author

Commented:
Hi Hhaest,

Ok i found hte Class librabries for WMI on Microsofts web site. There are a number of Netwotk classes. And i have found that i need to use a combination of Win32_NetworkAdapterConfiguration and Win32_NetworkAdapter and link it by Mac Address which is common in both calls to then be able to show in a select statement the details that i need

thanks allot for the help

http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx



cheers

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial