Net::DHCP::Watch - A class for monitoring a remote DHCPD server.
use Net::DHCP::Watch; # server name my $Server = 'dhcpd.mydomain.com'; # this machine ethernet address my $Ether = '01:23:45:67:89:ab'; # Net::DHCP::Watch object my $dhcpw = new Net::DHCP::Watch({ server => $Server, ether => $Ether }); # Open network $dhcpw->watch(); # Get status my $stat = $dhcpw->status; # print results if ( $stat->{Bad} ) print $stat->{Time}, ": Remote DHCP on $Server unavailable (",$stat->{Bad},").\n"; if ( $stat->{Ok} ) print $stat->{Time}, ": Remote DHCP on $Server online.\n";
Net::DHCP::Watch is a module to help monitor remote DHCP servers. It opens an udp socket to send and receive responses to and from a DHCP server. It stores the last connection status information.
At the time of this writing, the DHCP protocol has not defined yet a failover protocol. This module was written to help to write some simple code to implement this feature.
Creates a new Net::DHCP::Watch object. The parameters are passed throug a hash with the following keys:
DHCP server name or IP addres to be monitored (not the local machine performing the monitoring).
Ethernet address of the local machine performing the monitoring. Since there is no obvious way to determine that, it is mandatory. You can pass a 6 element array of bytes or a ':' separated string of hex values. In UNIX machines you can tipically do something like this:
my $ether = qx[ /sbin/ifconfig eth0 | tail +1 |\ head -1 | awk '{print \$5}']; chomp($ether);
The timeout for network operation (default 10s).
Prepares for monitoring.
Closes monitoring.
Try to comunicate with the server and returns the status in a hash. The hash contains three keywords. Ok will be true if the attempt completed successfully, Bad will be true if the attempt was not; they will contain the number of successful (or unsuccessful) contiguous attempts made. Time contains the GMT time string of the last attempt.
See the directory examples in source distribution for an example.
There should be a Net::DHCP class to handle the DHCP protocol.
On platform without alarm() function defined the monitoring cang hang forever if some network problems show up (cable problem)?
Evilio del Rio, edelrio@icm.csic.es
perl(1), IO::Socket(3), Net::hostent(3). RFCs 2131 and 2132.
Ralph Droms & Ted Lemon, The DHCP Handbook, MacMillan (Indianapolis), 1999.
To install Net::DHCP::Watch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::DHCP::Watch
CPAN shell
perl -MCPAN -e shell install Net::DHCP::Watch
For more information on module installation, please visit the detailed CPAN module installation guide.