2

I have Ip address of a device installed in the LAN Network. I need to get the device information like Name, mac address etc by passing this Ip address. When I tried to get the information using the following C# code, it throws exception "No such host is known". Devices may be printer / router or any other device.

IPHostEntry ip;
ip = Dns.GetHostEntry(ipaddress);
hostName = ip.HostName;

How to solve this issue. Any Ideas.

nessy hamsa
  • 185
  • 1
  • 12

2 Answers2

2

Ofcourse if you want access to remote machine you need to have enough privilege, then you can use WMI to run any query on destination machine and get info what you need. Also you can use Using WMI with C# if you want to use C#

Peyman
  • 3,068
  • 1
  • 18
  • 32
  • Thanks for the response. I didnt see any option for getting the device information by passing the ip address in WMI – nessy hamsa Apr 17 '15 at 04:44
  • Just search, you can fine so many samples like: http://www.c-sharpcorner.com/uploadfile/kirtan007/get-mac-address-of-network-card-using-wmi-and-C-Sharp/ Or http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/WMI+WMI~Get~MAC~Address~and~NIC~info.txt – Peyman Apr 17 '15 at 04:48
  • In WMI, we are querying information based on the type like USB, network adaptors etc. How to get the information of a device if we know only the ip address of the device, we dont know which are the types of devices connected. – nessy hamsa Apr 17 '15 at 05:47
  • Some devices support SNMP but it can be set off from the settings of the machine. Not all devices give info just from the ip address and if you dont have a properly configured DNS this query will not work. – Mert Gülsoy Apr 17 '15 at 07:37
0

try using

IPHostEntry ip;
ip = Dns.GetHostAddresses(ipaddress);
hostName = ip.HostName;

Regarding to why Dns.GetHostEntry gives you the specified error, I think it's due to the fact that DnsGetHostEntry will attempt to do a reverse DNS lookup before returning you the IP address. If reverse DNS lookup fails, it will give you "no such host is known".

Reference

Dns.GetHostEntry error conditions and resolution methods

Community
  • 1
  • 1
akhil kumar
  • 1,598
  • 1
  • 13
  • 26
  • `GetHostAddresses()` returns an array of IP addresses. How does that help the OP? They already have an IP address. – Peter Duniho Apr 17 '15 at 04:31
  • Thanks for the response. GetHostAddresses will return an array ip address it will not get any device information. @akhil kumar – nessy hamsa Apr 17 '15 at 04:49