Net::DHCPClient - A DHCP Client API
use Net::DHCPClient; my $dhcp = new Net::DHCPClient( maccaddr => '0a:0a:0a:0a:0a:0a', interface => 'eth0' ); $dhcp->discover( 61 => '0a 0a 0a 0a 0a 0a' );
This module provides methods for implementing a DHCP client. It allows perl scripts to interacts with DHCP servers.
This module is used by constructing a new DHCPClient object via the constructor method, providing it (minimally) with the machine address and the network interface that is to be used for the DHCP transaction with the DHCP server.
Information after each DHCP call is stored in the instance variables of the object. Refer to RFC2131 for the designations of the named fields. Options (sometimes called vendor extensions) are stored in an instance variable in the object called options as a references to a hash. The options themselves are keys by the decimal designation of the option, and the values of the hash are string representations of the hex values that should be passed to the DHCP server with the options. Please refer to RFC2132 for a complete listing.
Some common option fields are available through methods in this object for convenience. They are listed in this document.
This document is not a replacement for RFC2131 or RFC2132, and you will probably need a copy of them handy if you are coding DHCP clients.
The constructor is the only class method that should be invoked. It takes as its parameters minimally the machine address and the interface for which the DHCP transaction should take place.
Object methods must be invoked against objects created via the new method.
There are two kinds of object methods -- those that invoke DHCP transactions and those that interpret the results of a DHCP transaction. I am grouping them separately for this reason.
DHCPClient transaction object methods
All of the DHCPClient transaction methods take named parameters as their arguments, where paramters are named for the decimal representation of the options that can be set in the DHCP packet, and set to a string representation of the hex values that should be set for the named parameter in the DHCP packet. Whew. Fear not, examples are below.
The decline method declines an offer from a DHCP server.
The discover method broadcasts a DHCPDISCOVER on the local subnet.
The inform method requests information from a DHCP server.
The release method releases the lease of the IP address.
The request method requests a DHCP lease.
DHCPClient result object methods
These methods are built as conveniences to get the data that is contained in the result of a DHCP transaction returned in a usable form. All of the data can be had by going through the object instance variables by hand, but I would not recommend it. These methods will not return anything useful until a DHCP transaction has taken place.
Note -- unless otherwise noted, an IP address returned by an object method listed in this documentation should be considered to be a string containing the address is dotted notation.
Returns the broadcast address.
Returns the IP address of the client that made the request to the DHCP server.
Returns the domain name that the server has provided.
Returns a list of IP addresses of the domain name servers.
Returns a list of the IP addresses of the netbiod domain name servers (i.e. NT Domain servers)
Returns a list of IP address of the Network Time Protocol server.
Returns the IP address of the agent that relayed your DHCP request to the DHCP server (probably a router).
Returns a string indicating what the server reply was.
Returns a server identifier -- it is usually an IP address of the server, but does not necessarily need to be. This method assumes an IP address.
Returns the IP address of the DHCP server that handled your request.
Returns the subnet mask.
Returns a list of the IP addresses of the time servers.
Returns the IP address that the DHCP server has offered to your client.
Revision 1.0 2001/04/19 Initial release
Joshua Walgenbach Indiana Unversity firstname.lastname@example.org
Copyright 2000, Joshua Walgenbach All rights reserved
This program is free software; you can redistribute it and/or modify it under the terms of either:
b) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details.