Get IP address of remote client without DNS record in VB.Net

I have a Windows Forms Application running on a Terminal Server. I need to determine the IP addresses of each client machine.

I found a way to get the IP address for computers with DNS records (example below), but some of my thin clients were configured with static IP addresses and don't have a DNS name. Is there a way to determine the IP address of a remote client without a DNS name?

Dim clientName As String = My.Computer.Network.ClientName 
Dim IPHost As Net.IPHostEntry = Net.Dns.Resolve(clientName & "domain.com") 
Dim addresses As Net.IPAddress() = IPHost.AddressList
fullIP = addresses(0).ToString()

      

0


source to share


1 answer


To get the primary IP address, you can use:

System.Net.Dns.GetHostEntry("").AddressList(0).ToString

      



This can return an IP6 address, in which case you can try to find IP4 using:

Dim ipentry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry("")

For i As Integer = 0 To ipentry.AddressList.Count - 1
    MsgBox(System.Net.Dns.GetHostEntry("").AddressList(i).ToString)
Next

      

+1


source







All Articles