*** From dhcp-server -- To unsubscribe, see the end of this message. ***
At 08:25 AM 6/9/98 -0700, Darren Evans wrote:
> *** From dhcp-server -- To unsubscribe, see the end of this message. ***
>
>Converts from NT's DHCP Manager to ISC's configuration.
>Could do with a *complete* clean up, but works.
This version of your script converts current leases on a set of WinNT DHCP
servers into the format of dhcpd.leases.
#!/usr/local/bin/perl
# Simple script to convert NT DHCP -> ISC DHCP
# Use dhcpcmd from the NT Server Resource kit to dump the dhcp.mdb
# file to ascii
# Runs under ActivePerl (possibly under core/PerlMagic as well)
$domain = ".parc.xerox.com";
## hash key is server IP address, value is scope IP address
%dhservers = qw (
nnn.nnn.nnn.nnn
nnn.nnn.nnn.nnn
);
use Data::Dumper;
open(LEASES, ">dhcpd.leases.winnt") || die "Unable to open leases file\n";
foreach $server ( keys(%dhservers) ) {
open(FH, "dhcpcmd $server Enumclients $dhservers{$server} -v|" )
|| warn "Error opening $server\n" && next;
## weekday year/month/day hour:minute:second
use Time::CTime;
$starttime = &strftime("%w %Y/%M/%e %T", localtime());
$/ = "\nClientInfo :\n";
while ( defined($line = <FH> )) {
my ($ip, $subnet, $mac, $netbeuiname, $leaseend, $endtime) = ();
$_ = $line;
($ip) = $line =~ /^\tIP Address = (\d+\.\d+\.\d+\.\d+)/;
($subnet) = $line =~ /^\tSubnetMask = (\d+\.\d+\.\d+\.\d+)/;
($leaseend) = $line =~ m#.*\tExpires = (\d+).(\d+).(\d+) (\d+:\d+:\d+)#;
if (defined($leaseend)) {
$endtime = "0 $3/$1/$2 $4";
#print $endtime, "\n";
}
($mac) = $line =~ /\tClient Hardware Address =
((?:[0-9a-fA-F]{2}-){5}[0-9a-fA-F]{2})\./;
if (defined($mac)) {
$mac =~ tr/-/:/;
} else {
print STDERR "No MAC address: $line\n";
next;
}
($netbeuiname) = $line =~ /\tName = (\w+)/;
$netbeuiname =~ tr/A-Z/a-z/ if (defined($netbeuiname));
$comment = $line =~ /^\tComment = (\w+)\./;
if ( defined $ip && defined $mac && defined $endtime) {
print LEASES "lease $ip \{\n hardware ethernet $mac;\n";
print LEASES " starts $starttime;\n";
print LEASES " ends $endtime;\n";
print LEASES " hostname \"$netbeuiname\";\n"
if (defined($netbeuiname));
print LEASES "\}\n";
}
}
close(FH);
}
close LEASES;
__END__
#ClientInfo :
# IP Address = 192.80.30.254.
# SubnetMask = 255.255.255.0.
# Client Hardware Address = 00-00-11-11-11-11.
# Name = TERMITE.
# Comment = .
# Expires = 01/01/1601 01:00:00.
# Owner Host IP Address = 0.0.0.0.
# Owner Host NetBios Name = SUCK.
# Owner Host Name = (null).
--------------------------------------------------
dhcpd.leases(5) dhcpd.leases(5)
FORMAT
Lease descriptions are stored in a format that is parsed
by the same recursive descent parser used to read the
dhcpd.conf(5) and dhclient.conf(5) files. Currently, the
only declaration that is used in the dhcpd.leases file is
the lease declaration.
lease ip-address { statements... }
Each lease declaration include the single IP address that
has been leased to the client. The statements within the
braces define the duration of the lease and to whom it is
assigned.
The start and end time of a lease are recorded using the
``starts'' and ``ends'' statements:
starts date;
ends date;
Dates are specified as follows:
weekday year/month/day hour:minute:second
The weekday is present to make it easy for a human to tell
when a lease expires - it's specified as a number from
zero to six, with zero being Sunday. The day of week is
ignored on input. The year is specified with the century,
so it should generally be four digits except for really
long leases. The month is specified as a number starting
with 1 for January. The day of the month is likewise
specified starting with 1. The hour is a number between 0
and 23, the minute a number between 0 and 59, and the sec-
ond also a number between 0 and 59.
Lease times are specified in Greenwich Mean Time (GMT),
not in the local time zone. Since Greenwich is actually
on Daylight Savings Time part of the year, there is proba-
bly nowhere in the world where the times recorded on a
lease are always the same as wall clock times. On a unix
machine, one can often figure out the current time in GMT
by typing date -u.
The MAC address of the network interface that was used to
acquire the lease is recorded with the hardware statement:
hardware hardware-type mac-address;
The MAC address is specified as a series of hexadecimal
octets, seperated by colons.
If the client used a client identifier to acquire its
address, the client identifier is recorded using the uid
statement:
uid client-identifier;
The client identifier is recorded as a series of hexadeci-
mal octets, regardless of whether the client specifies an
ASCII string or uses the newer hardware type/MAC address
format.
If the client sends a hostname using the Client Hostname
option, as specified in some versions of the DHCP-DNS
Interaction draft, that hostname is recorded using the
client-hostname statement.
client-hostname "hostname";
If the client sends its hostname using the Hostname
option, as Windows 95 does, it is recorded using the
hostname statement.
hostname "hostname";
The DHCP server may determine that a lease has been mis-
used in some way, either because a client that has been
assigned a lease NAKs it, or because the server's own
attempt to see if an address is in use prior to reusing it
reveals that the address is in fact already in use. In
that case, the abandoned statement will be used to indi-
cate that the lease should not be reassigned.
abandoned;
Abandoned leases are reclaimed automatically. When a
client asks for a new address, and the server finds that
there are no new addresses, it checks to see if there are
any abandoned leases, and allocates the least recently
abandoned lease. The standard mechanisms for checking
for lease address conflicts are still followed, so if the
abandoned lease's IP address is still in use, it will be
reabandoned.
If a client requests an abandoned address, the server
assumes that the reason the address was abandoned was that
the lease file was corrupted, and that the client is the
machine that responded when the lease was probed, causing
it to be abandoned. In that case, the address is immedi-
ately assigned to the client.
--------------------------------------------------
------------------------------------------------------------------------------
To unsubscribe from this list, please visit http://www.fugue.com/dhcp/lists
If you are without web access, or if you are having trouble with the web page,
please send mail to [EMAIL PROTECTED] Please try to use the web
page first - it will take a long time for your request to be processed by hand.
------------------------------------------------------------------------------