Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

printing - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Exact same way.

\1.2.3.4somesharedprinter

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:

\Bobprinty

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.4printy

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.5something

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...