Support module for mdns service discovery (apple's bonjour)
use Net::Bonjour;
my $res = Net::Bonjour->new(<service>[, <protocol>]); $res->discover;
foreach my $entry ( $res->entries ) { print $entry->name, \*(L"\n\*(R"; }
Net::Bonjour::Entry is a module used to manage entries returned by a mDNS service discovery (Apple's Bonjour). See Net::Bonjour for more information.
Creates a new Net::Bonjour::Entry object. The optional argument defines the fully qualifed domain name (\s-1FQDN\s0) of the entry. Normal usage of the Net::Bonjour module will not require the construction of Net::Bonjour::Entry objects, as they are automatically created during the discovery process.
Returns the \s-1IP\s0 address of the entry.
Returns all the current attributes in the form of hashed array.
Returns the specified attribute from the \s-1TXT\s0 record of the entry. \s-1TXT\s0 records are used to specify additional information, e.g. path for http.
Returns an \s-1DNS\s0 answer packet of the entry. The output will be in the format of a Net::DNS::Packet object. The record type designates the resource record to answer with, i.e. \s-1PTR\s0, \s-1SRV\s0, or \s-1TXT\s0. The default is \s-1PTR\s0.
Reloads the information for the entry via mDNS.
Returns the fully qualifed domain name (\s-1FQDN\s0) of entry. An example \s-1FQDN\s0 is server._afpovertcp._tcp.local
Returns the hostname of the server, e.g. 'server.local'.
Returns the name of the entry. In the case of the fqdn example, the name would be 'server'. This name may not be the hostname of the server. For example, names for presence/tcp will be the name of the user and http/tcp will be title of the web resource.
Returns the \s-1TCP\s0 or \s-1UDP\s0 port of the entry.
Returns the binary socket address for the resource and can be used directly to bind() sockets.
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>";
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;
Net::Bonjour
This library is free software and can be distributed or modified under the same terms as Perl itself.
Bonjour (in this context) is a trademark of Apple Computer, Inc.
The Net::Bonjour::Entry module was created by George Chlipala <[email protected]>