Getting IP Information From Computer

muabao

Member
Joined
Dec 20, 2007
Messages
6
Programming Experience
Beginner
I'm trying to write a sub to print out all the IP information for a host computer.

Here's what I have to print the Ip addresses to all the Ethernet Adapters:
VB.NET:
Dim LocalHostName = Dns.GetHostName()
Dim IpCollection As New Collection
Dim i As Integer
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(LocalHostName)
Dim IpA() As Net.IPAddress = h.AddressList
For i = 0 To IpA.GetUpperBound(0)
     IpCollection.Add(IpA(i).ToString)
     MsgBox(IpA(i).ToString)
Next

The other piece of information the Ethernet Adapter to which the IP address is tied to (output similar to ipconfig.exe where it prints out "Ethernet adapter Local Area Connection 2:" etc.).

Any help is greatly appreciated.

MB
 
Oops, my post was not clear in what I needed help with...

I'd like to find a way to get the Ethernet Adapter's other pertinent information that's tied to the IP address. For ex., for ipadress 192.168.16.10, the Ethernet Adapter is "Local Area Connection 1"....

Thanks,
MB
 
Getting IP Address For A Specific Adapter

Sorry about the double-posting but I hope this time around it's more clear as to exactly what I'm trying to do:

I'd like to get the ip address for an adapter ONLY if it's "Local Area Connection"

Here's the code I have so far:

VB.NET:
   Sub GetLocalIp()

        Dim nwInterfaces() As System.Net.NetworkInformation.NetworkInterface = _
            System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()

        For Each currentInterface As System.Net.NetworkInformation.NetworkInterface In nwInterfaces
            If currentInterface.OperationalStatus = System.Net.NetworkInformation.OperationalStatus.Up _
                And currentInterface.NetworkInterfaceType.ToString() = "Ethernet" Then

                If Strings.StrComp(currentInterface.Name.ToString(), "Local Area Connection") = 0 Then
                    'How to get the IP address to this adapter?
                End If
            End If
        Next
End Sub

Again, any help is greatly appreciated.

Thanks,
MB
 
This outputs to Output window:
VB.NET:
For Each ni As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces
    Console.WriteLine("Name: " & ni.Name)
    Console.WriteLine("Description: " & ni.Description)
    For Each ip As Net.IPAddress In ni.GetIPProperties.DnsAddresses
        Console.WriteLine(ip.ToString)
    Next
Next
(Imports System.Net.NetworkInformation)

edit: Your new thread was merged, see you've discovered NetworkInterface...
there are many different IP addresses related to a network interface, the IP you probably seek is the Unicast address:
VB.NET:
For Each ip As UnicastIPAddressInformation In ni.GetIPProperties.UnicastAddresses
    Console.WriteLine(ip.Address.ToString)
Next
 
Back
Top