P
Paul Bromley
How do I know which IP address is active??
I have created the following class and this works well, but the first
address it obtains on my machine is not the active one - in fact I do not
know what NIC it refers to the second one in the addresslist is the current
one (mIpAddr(1).ToString()). How can I test for the current active IP
address?? Many thanks in anticipation.
Many thanks
Paul Bromley
Imports System.Net
Public Class CGetLocalIPAddress
Dim sIpAddr As String
'Dim myLocalIP As New CGetLocalIPAddress
Public Sub New()
GetLocalIPAddress()
End Sub
Private Sub GetLocalIPAddress()
Dim ipEntry As IPHostEntry = Dns.GetHostByName(Environment.MachineName)
Dim mIpAddr As IPAddress() = ipEntry.AddressList
Dim i As Integer
sIpAddr = mIpAddr(1).ToString()
End Sub
Public Property LocalIPAddress() As String
Get
Return sIpAddr
End Get
Set(ByVal Value As String)
sIpAddr = Value
End Set
End Property
End Class
I have created the following class and this works well, but the first
address it obtains on my machine is not the active one - in fact I do not
know what NIC it refers to the second one in the addresslist is the current
one (mIpAddr(1).ToString()). How can I test for the current active IP
address?? Many thanks in anticipation.
Many thanks
Paul Bromley
Imports System.Net
Public Class CGetLocalIPAddress
Dim sIpAddr As String
'Dim myLocalIP As New CGetLocalIPAddress
Public Sub New()
GetLocalIPAddress()
End Sub
Private Sub GetLocalIPAddress()
Dim ipEntry As IPHostEntry = Dns.GetHostByName(Environment.MachineName)
Dim mIpAddr As IPAddress() = ipEntry.AddressList
Dim i As Integer
sIpAddr = mIpAddr(1).ToString()
End Sub
Public Property LocalIPAddress() As String
Get
Return sIpAddr
End Get
Set(ByVal Value As String)
sIpAddr = Value
End Set
End Property
End Class