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

前端 未结 2 1797
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 07:49

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 answ

相关标签:
2条回答
  • 2020-12-20 08:28

    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
    
    0 讨论(0)
  • 2020-12-20 08:31

    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.

    0 讨论(0)
提交回复
热议问题