I'm trying to get an IP address from computer name in same network... Something like CMD command "nbtstat -a COMPNAME" in C# windows application
Asked
Active
Viewed 6,901 times
3
-
I tried all sort of things, but nothing worth mention – Dudipoli Oct 30 '12 at 08:09
-
possible duplicate of [Get IP address of user computer in C#](http://stackoverflow.com/questions/7737499/get-ip-address-of-user-computer-in-c-sharp) – skolima Oct 30 '12 at 11:41
2 Answers
12
Use Dns.GetHostAddresses
:
Dns.GetHostAddresses("some pc name")
.ToList()
.ForEach(a => Console.WriteLine(a.ToString()));

horgh
- 17,918
- 22
- 68
- 123
-
@Dudipoli probably you need to add `using System.Net;` to your using list – horgh Oct 30 '12 at 08:13
-
The problem was in one of the network card definition. Each time i tried to get his ip, i got no such host that's why i thought something was wrong with the code. Thanks – Dudipoli Oct 30 '12 at 08:30
-
-1
Try this method:
Dns.GetHostName();
http://msdn.microsoft.com/en-us/library/system.net.dns.gethostname.aspx

Raptor
- 53,206
- 45
- 230
- 366
-
That gives me my computer name... I already have the computer name but now i'm trying to get his ip, from the computer name – Dudipoli Oct 30 '12 at 08:13