Feed on
Posts
Comments

If you ever need to get the IP Address of the local computer you need look no further than the System.Net.Dns class.  Since a computer can have more than one IP Address you need to iterate throught the collection.  Here is a sample that fills a listbox with all the IP addresses from your computer.

Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

 
 

 

Try

 ‘ IpHostEntry is a helper class for the Dns class
 ‘ Environment.MachineName should return local computername

Dim hostServer As
IPHostEntry = Dns.Resolve(Environment.MachineName) 

‘ assume that we only have IPv4 address
‘ if you are using IPv6 then you can test with ip.AddressFamily For Each ip As IPAddress In

hostServer.AddressList 

‘ Display the server IP address in the standard format.
‘ IPv4 it will be in dotted-quad notation
‘ IPv6 it will be in colon-hexadecimal notation.    Me.ListBox1.Items.Add(ip.ToString) 

Next

Catch ex As Exception
   Console.WriteLine(ex.Message)
End Try
 
 
 
 

 

End Sub


Leave a Reply