3

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

Mxyk
  • 10,678
  • 16
  • 57
  • 76
Dudipoli
  • 471
  • 1
  • 5
  • 12
  • 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 Answers2

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
  • @Dudipoli Glad to know, this helped you – horgh Oct 30 '12 at 08:31
-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