How to get the IP address of a network printer with a port name using the Win32 API?

How to get the IP address of a network printer with a port name using win32 API?

I tried looking in PRINTER_INFO_* structs, but it seems he is not there.

+5
source share
4 answers

I don't think there is a standard way to get an IP address. Perhaps there are various incompatible implementations of network port monitors. For my network printer, the IP address is part of the port name (for example, IP_192_168.1.104). If it has this form, then you can take it apart, but I do not think it is universal.

EnumPorts, , , IP-.

+2

PRINTER_INFO_2, ip , : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\ TCP/IP\Ports ip store "HostName"

+3

IP-, IP- ( Ethernet-) ( , ). .

, IP-. , .

Assuming you have a printer name, you need to request a name service for your domain. This service maps network addresses to "symbolic" names.

Using winsock2 api, I find what gethostbynameyou need. This will provide information about the host of your printer by its name.

+2
source

Just use the advanced apis printer, dynamic call

0
source

All Articles