Net::Bonjour(3pm)
β¨ NAME β¨
Net::Bonjour β the module for DNS service discovery (aka Apple's Bonjour) π
This is the Net::Bonjour(3pm) page, straight out of the User Contributed Perl Documentation, and honestly? It's giving iconic. Let's go π
π SYNOPSIS π
okay so first up, the classic way, bestie:
use Net::Bonjour;
my $res = Net::Bonjour->new(<service>[, <protocol>]);
$res->discover;
foreach my $entry ( $res->entries ) {
printf "%s %s:%s\n", $entry->name, $entry->address, $entry->port;
}
Or the cyclical way, for when you're feeling extra:
use Net::Bonjour;
my $res = Net::Bonjour->new(<service>[, <protocol>]);
$res->discover;
while ( 1 ) {
foreach my $entry ( $res->entries ) {
print $entry->name, "\n";
}
$res->discover;
}
π¦ DESCRIPTION π¦
Net::Bonjour is a whole set of modules that let you discover local services via multicast DNS (mDNS) or enterprise services via traditional DNS. Apple Computer branded this whole service-discovery method as Bonjour. no cap β¨
π Base Object
The base object is of the Net::Bonjour class, and it's the one holding the resolver for DNS service discovery. main character energy fr fr π
π Entry Object
The base object (Net::Bonjour) hands you back entry objects of the class Net::Bonjour::Entry. cute, right? π
π METHODS π
π new([<service>, <protocol>, <domain>])
Creates a brand-new Net::Bonjour discovery object, slay π
- The first argument is the service you wanna discover β think
http,ftp,afpovertcp, andssh. - The second argument is the protocol, i.e.
tcporudp. The default protocol isTCP. - The third argument is the discovery domain, and the default is
'local'.
Heads up bestie: if you pass no arguments at all, the resulting Net::Bonjour object will be empty and it will not perform an automatic discovery when it's created. Empty. Nothing. Nada π
π all_services([<domain>])
Returns an array of new Net::Renedezvous objects, one for each service type advertised in the domain. The argument is the discovery domain, and the default is 'local'.
Please note (fr fr): the resultingNet::Bonjourobjects will not have performed a discovery during creation. So you gotta run the discovery process before you go retrieving a list of entries for thatNet::Bonjourobject. iykyk π
π domain([<domain>])
Gets/sets the current discovery domain. By default the discovery domain is 'local'. Discovery for the 'local' domain goes down via MDNS, while all other domains get done via traditional DNS. two different vibes, same module π«
π discover
Repeats the discovery process and reloads the entry list from this discovery. refresh, reset, rebirth β¨
π entries
Returns an array of Net::Renedezvous::Entry objects for the last discovery. it's giving results, periodt π
π protocol([<protocol>])
Gets/sets the current protocol of the service type, i.e. TCP or UDP.
Little note bestie: this is not the protocol for the DNS connection. don't get it twisted π«Ά
π service([<service type>])
Gets/sets the current service type. simple as that, queen π
π shift_entry
Shifts off the first entry of the last discovery. The returned object will be a Net::Bonjour::Entry object. bye bye first entry, we hardly knew ye π
π₯ EXAMPLES π₯
πΈ Print out a list of local websites
print "<HTML><TITLE>Local Websites</TITLE>";
use Net::Bonjour;
my $res = Net::Bonjour->new('http');
$res->discover;
foreach my $entry ( $res->entries) {
printf "<A HREF='http://%s%s'>%s</A><BR>", $entry->address,
$entry->attribute('path'), $entry->name;
}
print "</HTML>";
πΈ Find a service and connect to it
use Socket;
use Net::Bonjour;
my $res = Net::Bonjour->new('custom');
$res->discover;
my $entry = $res->shift_entry;
socket SOCK, PF_INET, SOCK_STREAM, scalar(getprotobyname('tcp'));
connect SOCK, $entry->sockaddr;
print SOCK "Send a message to the service";
while ($line = <SOCK>) { print $line; }
close SOCK;
πΈ Find all service types and print.
use Net::Bonjour;
foreach my $res ( Net::Bonjour->all_services ) {
printf "%s (%s)\n", $res->service, $res->protocol;
}
πΈ Find and print all service types and entries.
use Net::Bonjour;
foreach my $res ( Net::Bonjour->all_services ) {
printf "-- %s (%s) ---\n", $res->service, $res->protocol;
$res->discover;
foreach my $entry ( $res->entries) {
printf "\t%s (%s:%s)\n", $entry->name, $entry->address, $entry->port;
}
}
π§ SEE ALSO π§
Net::Bonjour::Entryβ go read it next, bestie π
π COPYRIGHT π
This library is free software and can be distributed or modified under the same terms as Perl itself. slay π
Bonjour (in this context) is a trademark of Apple Computer, Inc. π
β AUTHORS β
The Net::Bonjour module was created by George Chlipala <george@walnutcs.com>. icon behavior, honestly π«Ά
and that's the whole page, bestie!! π this one came from perl v5.32.0, dated 2021-01-05, and it lives at Net::Bonjour(3pm). go discover some services, you got this π
β¨π¦
π¦ where this page comes from
- debian bookworm: libnet-bonjour-perl 0.96-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnet-bonjour-perl 0.96-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libnet-bonjour-perl 0.96-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-bonjour-perl 0.96-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-bonjour-perl 0.96-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-bonjour-perl 0.96-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms