Anthony Gags

Anthony Gags

  • 2.1k
  • 11
  • 1.3k

Get specific IP address of PC, regardless of which adapter.

Jun 27 2017 11:10 PM
Hi There,
i have a program that is trying to get the IP address of any PC on our netowrk 
I have been using the below semi-successfully, yet it will only work if an IP  address actually exists in the first list.
 
 
string HostName = Dns.GetHostName(); 
 Dns.GetHostEntry(HostName).AddressList[0].ToString()
 
 
however,
the problem  arises when the entry 0 does not exist, and it is actually entry 1 or 2 for that matter..
 
How can i go around this so that no matter which entry actually has the IP address of  192.168.XXX.XXX, it will p[ick it up and tell me the whole IP.
 
Thanks in advance 
 

Answers (3)