Morgan Herlocker
Morgan Herlocker

Reputation: 1483

How to access a printer name from IP on network in C#?

I can get to the printer with the name "\\xxxx\[name of printer]" but have no idea how to access this with only the IP of the printer. Any ideas?

EDIT: The answers seem to suggest that I can simply swap out the printer name for the IP address of the printer, however this does not seem to be the case. Any MORE ideas?

UPDATE: the reason for addressing the printer as an IP is that the networking guys gave all of the printers the same share name, so I have no way to distinguish them, other than their IP.

Upvotes: 1

Views: 20528

Answers (2)

Brad
Brad

Reputation: 163603

Exact same way.

\\1.2.3.4\somesharedprinter

Where "1.2.3.4" is the IP address of whatever is sharing the printer.

Edit:

Even if your printer has a built-in network interface, let's mentally separate the printer from the print server for a moment.

When you have a computer, let's call it Bob, and you share a printer, let's call it printy, you can access it like this:

\\Bob\printy

The first part of this address is the hostname or IP address. If Bob's IP address was 1.2.3.4, you could easily use this address instead:

\\1.2.3.4\printy

Now it sounds like your printer has a built-in print server which allows it to essentially share itself over the network. Most of these print servers are completely compatible with Windows File/Printer Sharing. So if the printer's IP is 2.3.4.5, we could use an address like this:

\\2.3.4.5\something

You want the something part, yes? To do this we need to enumerate the shares on that print server. You can do that with the code found here: http://www.codeproject.com/KB/IP/networkshares.aspx

To my knowledge, there is no managed way to get a list of shares on a server, so the link above is probably your best option for now.

I should also note that another common standard for print servers is the HP Jet Direct. You can't (well you can, but it's hackish) print to these until you install the printer on your system. To do this, you would go to Printers, Add Printer, choose a "local" (yes, counterintuitive) printer, then for port choose TCP/IP, and then enter the IP address.

Upvotes: 6

Aaron McIver
Aaron McIver

Reputation: 24723

If it has a host name it has an IP and they can be interchanged as needed.

\\MyMachine\MyPrinter

...equates to...

\\10.0.0.1\MyPrinter

If your printer is not on a machine and is a networked printer it will have its own IP address which you can use.

\\MyPrinter

...equates to...

\\10.0.0.2

Upvotes: 2

Related Questions