Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the IP address of a network printer given the port name using the Win32 API?

How can I get the IP address of a network printer given the port name, using win32 API?

I tried looking into the PRINTER_INFO_* structs, but it seems it is not present there.

like image 938
sourabh jaiswal Avatar asked Oct 19 '09 09:10

sourabh jaiswal


2 Answers

you can get the port name by PRINTER_INFO_2,and the get the ip from the registry,the path is: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports the ip store in "HostName"

like image 93
xinsheng Avatar answered Sep 21 '22 00:09

xinsheng


I don't think there's a standard way to get the IP address. There are probably different incompatible implementations of network port monitors. For my network printer, the IP address is part of the port name (e.g., IP_192_168.1.104). If it's of that form, then you might be able to parse it out, but I don't think this is universal.

Using EnumPorts you can determine if it's a network printer, but I still don't see a way to get the IP address.

like image 29
Adrian McCarthy Avatar answered Sep 21 '22 00:09

Adrian McCarthy