I ma using VB.net 2003. I thought this would be easy to do and apologise for
asking again - I have been trying. I would like to obtain the ACTIVE local
IP address - i.e. the one connected to the network and active. I have tried
the code below, and have iterated through a number of possible adaptors to
poulate a listbox. This is not ideal, but I could live with it. NOTE - all
of the machines I will be running it on will have a permanent broadband
connection (if that makes life any easier). The problem is that it does not
always seem to work on all PCs I have tried it with. The code I have used is
as follows:-
Dim i As Integer
Dim h As System.Net.IPHo stEntry =
System.Net.Dns. GetHostByName(S ystem.Net.Dns.G etHostName)
Try : sIpAddr0 = (CType(h.Addres sList.GetValue( 0), IPAddress).ToSt ring) :
Catch : End Try
Try : sIpAddr1 = (CType(h.Addres sList.GetValue( 1), IPAddress).ToSt ring) :
Catch : End Try
Try : sIpAddr2 = (CType(h.Addres sList.GetValue( 2), IPAddress).ToSt ring) :
Catch : End Try
Many thanks in anticipation,
Paul Bromley
asking again - I have been trying. I would like to obtain the ACTIVE local
IP address - i.e. the one connected to the network and active. I have tried
the code below, and have iterated through a number of possible adaptors to
poulate a listbox. This is not ideal, but I could live with it. NOTE - all
of the machines I will be running it on will have a permanent broadband
connection (if that makes life any easier). The problem is that it does not
always seem to work on all PCs I have tried it with. The code I have used is
as follows:-
Dim i As Integer
Dim h As System.Net.IPHo stEntry =
System.Net.Dns. GetHostByName(S ystem.Net.Dns.G etHostName)
Try : sIpAddr0 = (CType(h.Addres sList.GetValue( 0), IPAddress).ToSt ring) :
Catch : End Try
Try : sIpAddr1 = (CType(h.Addres sList.GetValue( 1), IPAddress).ToSt ring) :
Catch : End Try
Try : sIpAddr2 = (CType(h.Addres sList.GetValue( 2), IPAddress).ToSt ring) :
Catch : End Try
Many thanks in anticipation,
Paul Bromley