How to use the command avahi-browse (with examples)

How to use the command avahi-browse (with examples)

Avahi-browse is a command-line tool that allows users to discover and browse services and hosts exposed on the local network using mDNS/DNS-SD. It is compatible with Bonjour (Zeroconf) commonly found in Apple devices. This article will illustrate various use cases of the avahi-browse command along with their respective code, motivations, explanations, and example outputs.

Use case 1: List services available on the local network along with their addresses and ports, ignoring ones on the local machine

Code:

avahi-browse --all --resolve --ignore-local

Motivation: This use case is useful when you want to discover and explore network services available in your local network excluding the services running on your local machine. It helps to identify and connect with external services that can enhance your network functionality.

Explanation:

  • --all: Displays all services, whether they are currently available or not.
  • --resolve: Resolves the IP addresses and port numbers of the discovered services.
  • --ignore-local: Excludes services on the local machine from the results.

Example output:

+  en0 IPv6 Printer                                Internet Printer     local
=  en0 IPv6 Printer                                Internet Printer     local
   hostname = [example.local]
   address = [fe80::1234:5678%en0]
   port = [631]

Use case 2: Quickly list services in the local network in SSV format for scripts

Code:

avahi-browse --all --terminate --parsable

Motivation: When you need a script-friendly output to process the discovered network services automatically, using the SSV (semicolon-separated values) format can simplify the task. This use case can be helpful in automation or integration scenarios.

Explanation:

  • --all: Displays all services, including the currently available ones.
  • --terminate: Terminates the command after the first reply received.
  • --parsable: Outputs the results in a machine-readable format.

Example output:

=;eth0;IPv4;My Music;_daap._tcp;local;My Music Server;My Music.foo;192.168.0.100;3689;
=;eth0;IPv4;My Printer;_ipp._tcp;local;My Printer Service;My Printer.foo;192.168.0.101;631;

Use case 3: List domains in the neighborhood

Code:

avahi-browse --browse-domains

Motivation: This use case is handy when you want to discover and connect to domains in your local network. It enables you to explore and understand the available domains, which can be useful for various networking purposes.

Explanation:

  • --browse-domains: Lists the available domains in the neighborhood.

Example output:

+  en0 IPv6 example.local                                               ptr    local
+  en0 IPv4 example.local                                          ptr    local

Use case 4: Limit the search to a particular domain

Code:

avahi-browse --all --domain=example.local

Motivation: This use case aims to narrow down the search specifically to a particular domain. It assists in discovering and interacting with services and hosts within the specified domain, providing a focused view of the network resources.

Explanation:

  • --all: Displays all services, including the currently available ones.
  • --domain=domain: Limits the search to the specified domain.

Example output:

+  en0 IPv6 example.local

Related Posts

How to use the command Measure-Command (with examples)

How to use the command Measure-Command (with examples)

Measure-Command is a command available in PowerShell that measures the time it takes to run script blocks and cmdlets.

Read More
How to use the command 'chfn' (with examples)

How to use the command 'chfn' (with examples)

The ‘chfn’ command is used to update the information displayed by the ‘finger’ command for a specific user.

Read More
How to use the command 'swc' (with examples)

How to use the command 'swc' (with examples)

The swc command is a JavaScript and TypeScript compiler written in Rust.

Read More