How do I get IP of installed network printer

Using lpoptions

lpoptions  -p <printer_name> | awk '{for (i=1; i<=NF; i++) {if ($i ~ /device-uri/) {print $i}}}'

Example

$ lpoptions  -p TOSHIBA_e-STUDIO2330C | awk '{for (i=1; i<=NF; i++) {if ($i ~ /device-uri/) {print $i}}}'
device-uri=socket://192.168.20.43

To get an overview lpinfo

Example

$ lpinfo -v | grep -P '://'
network dnssd://HP%20LaserJet%201022n._pdl-datastream._tcp.local/
network dnssd://TOSHIBA%20e-STUDIO2540C-07279076._printer._tcp.local/
network socket://192.168.20.201
network socket://192.168.20.203
network socket://192.168.20.204
network socket://192.168.20.205
network socket://192.168.20.206
network socket://192.168.20.207
network socket://192.168.20.43

or nmap

nmap -sT <adress_or_address_range>

and grep the service printer

Example

$ nmap -sT 192.168.20.43

Starting Nmap 6.47 ( http://nmap.org ) at 2015-07-03 08:38 CEST
Nmap scan report for 192.168.20.43
Host is up (0.0017s latency).
Not shown: 991 closed ports
PORT     STATE SERVICE
21/tcp   open  ftp
25/tcp   open  smtp
80/tcp   open  http
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
515/tcp  open  printer
631/tcp  open  ipp
8080/tcp open  http-proxy
9100/tcp open  jetdirect

To expands on @JUH's solution above...

avahi-browse --all -t -r

Is the proper solution for autodiscover printers.

Unfortunately many printers simply don't expose their IP address in any usable form to you, the end user. This is by design. https://www.cups.org/doc/network.html

Most network printers support a protocol known as Bonjour, which is a combination of zero-configuration networking (ZeroConf), multicast DNS (mDNS), and DNS service discovery (DNS-SD) standards published by the Internet Engineering Task Force (IETF), the same group that defined TCP/IP and all of the networking we use today

Quoting the mDNS page:

When an mDNS client needs to resolve a hostname, it sends an IP multicast query message that asks the host having that name to identify itself. That target machine then multicasts a message that includes its IP address. All machines in that subnet can then use that information to update their mDNS caches. Any host can relinquish its claim to a name by sending a response packet with a time to live (TTL) equal to zero.

So to properly find the IP address of an mDNS printer, you'd need a tool capable of reading the cache.

Quoting one of the OP's comments:

Thanks. In my case, lpoptions shows indeed a lot of info, but not the IP. The concerned field looks like device-uri=hp:/net/hp_LaserJet_2420?zc=HP2420ROOMXXX, so again the same as what I get from GUI tools. So I assume the IP isn't stored in my machine...

This makes avahi-browse the best tool for the job... (or if you got here looking for a Mac utility, Apple offers one called dns-sd)

Quoting the Avahi page:

Avahi is a system which facilitates service discovery on a local network via the mDNS/DNS-SD protocol suite. This enables you to plug your laptop or computer into a network and instantly be able to view other people who you can chat with, find printers to print to or find files being shared. Compatible technology is found in Apple MacOS X (branded "Bonjour" and sometimes "Zeroconf").

Avahi is primarily targetted at Linux systems and ships by default in most distributions. It is not ported to Windows at this stage, but will run on many other BSD-like systems. The primary API is D-Bus and is required for usage of most of Avahi, however services can be published using an XML service definition placed in /etc/avahi/services.

See also the nss-mdns project, which allows hostname lookup of *.local hostnames via mDNS in all system programs using nsswitch


According to the HP Laserjet 2400-series User Guide, the IP address is available on the control panel of the printer itself.

enter image description here

Tags:

Ip

Printing