nessy hamsa
nessy hamsa

Reputation: 185

How to get device information by passing the IP address using C#.net

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.

Upvotes: 2

Views: 4600

Answers (2)

Peyman
Peyman

Reputation: 3138

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#

Upvotes: 2

akhil kumar
akhil kumar

Reputation: 1618

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

Upvotes: 0

Related Questions