Macs, printers, NAS boxes and a lot of smart home gear announce themselves on the local network with Bonjour. That’s how the Finder sidebar and the print dialog find things without you typing an IP address. With dns-sd you can watch those announcements yourself.
dns-sd -B _ssh._tcp
-B browses for a service type. This example lists every machine that announces an SSH server, such as a Mac with Remote Login switched on. Each line shows whether a service was added or removed, the interface, the domain (almost always local. at home) and the instance name. Other types work the same way: _smb._tcp for file sharing, _http._tcp for web pages, _ipp._tcp for printers.
Once you have a name, -L looks up how to reach it, with the host name, the port and any extra TXT attributes:
dns-sd -L "Office Mac" _ssh._tcp
dns-sd -G v4 office-mac.local
-G v4 then turns that .local host name into an IPv4 address (v6 and v4v6 also work). I like this when a device has a vague name in the Finder and I want to know which IP address and port it really uses.
The caveat: dns-sd never exits by itself. It keeps listening and prints new Add and Remove events as devices come and go, so stop it with Control-C. You also only see devices on your own network segment, so a server behind another router or on a separate VLAN won’t show up. And leave -R, the option that advertises a service, for testing. Apple’s own man page points out that announcing a service that doesn’t exist only confuses other people on the network.
Further reading: dns-sd(1) man page (Apple mDNSResponder source)