-2

I need to get the network device name for the given IP address.For example a printer connected in a network.I have the IP address of the printer but I need to access its name using the corresponding IP address. I tried with dns.getHostByaddress(), but it didn't worked out properly.Let me know if any other solution exists.

 string c = Dns.GetHostByAddress("xxx.xxx.x.xxx").HostName;
 pdoc.PrinterSettings.PrinterName =c ;

It is a windows stand alone application using c# vs2010.

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
user3541403
  • 247
  • 1
  • 3
  • 18
  • I want the device name and when I am using gethost by address it throws the error "The requested name is valid, but no data of the requested type was found". – user3541403 Sep 18 '14 at 09:48
  • To be precise I wnat to set the IPaddress of the printe as mentioned below to access the printer connected in the network – user3541403 Sep 18 '14 at 09:49
  • pdoc.PrinterSettings.PrinterName ="IPaddress" ; – user3541403 Sep 18 '14 at 09:50
  • Do printers have hostnames? – bobbyalex Sep 18 '14 at 09:52
  • 1
    `PrinterSettings.PrinterName` must be set to a printer name the local computer knows. This has no relation to the IP address. Please explain how you obtain the IP address instead of the locally known printer names and why you want to use it this way. See also [Print to a network printer using IP address](http://stackoverflow.com/questions/25823208/print-to-a-network-printer-using-ip-address), [How to access a printer name from IP on network in C#?](http://stackoverflow.com/questions/4629867/how-to-access-a-printer-name-from-ip-on-network-in-c). – CodeCaster Sep 18 '14 at 09:52
  • I'd recommend updating your question rather than adding comments if you want to clarify your question. – Daniel Kelley Sep 18 '14 at 09:53
  • this was my actual question,the link which u have provided was actually posted by me – user3541403 Sep 18 '14 at 09:56
  • http://stackoverflow.com/questions/25823208/print-to-a-network-printer-using-ip-address/25823262?noredirect=1#comment40397646_25823262 – user3541403 Sep 18 '14 at 09:57
  • Then please continue in that question. – CodeCaster Sep 18 '14 at 10:02
  • I dint get proper solution from that question – user3541403 Sep 18 '14 at 10:08
  • is there any updates on this issue? it does not work with ip addresss... I have "files to be printed" at a DB table from another app... those users choose a printer an its ip is stored... no printer name is available... so... How to set the printername since I only have the ip adress? – Fernando Torres May 26 '15 at 19:30

1 Answers1

0

You cannot get the "DeviceName" by the ip itself. DNS-Names only exist at a DNS-Server (or netbios in such an environment) which hold the information about it - if you call "Dns.GetHostByAddress" you are always query the DNS-Server. If you are using DHCP on the devices, the dns entry will be updated automatically (if configured well). Else you have to configure the DNS-Server ip-address on the device and hope that this device is able to Register at the DNS (permissions and supported by your device). Another way (which i not prefer) is to add the entries to the DNS manually. You can force dnsregistration on a Windows machine by executing "ipconfig /registerdns"

Cadburry
  • 1,844
  • 10
  • 21