DHCPCMD

Dump your DHCP database into an ASCII file.

Mark Minasi

May 31, 1998

3 Min Read
ITPro Today logo in a gray background | ITPro Today

A command-line DHCP manager

About once a month, I get a letter from a reader looking for a program that can generate an ASCII text file showing all of a system's existing Dynamic Host Configuration Protocol (DHCP) leases. Fortunately, a tool in Microsoft Windows NT Server 4.0 Resource Kit offers a solution to this common problem.

The Problem
The DHCP service simplifies assigning IP addresses to computers on a network. After you designate a range of IP addresses (a scope in DHCP terminology) on a Windows NT server that acts as a DHCP server, you no longer need to manually enter IP addresses on your NT or other Windows workstations. Like magic, your PCs find the DHCP server, and the DHCP server gives them the next available IP address automatically.

Because DHCP gives the addresses only for a fixed length of time, the PCs lease their IP addresses from the server. The DHCP Manager that comes with NT Server lets you see a list of all currently-leased IP addresses, or active leases, but you can view them only through the DHCP Manager GUI.

You cannot use the DHCP Manager to output a list of active leases to a file. However, you might want to dump lease information to an ASCII file for several reasons: You need to feed information about active leases into your Domain Name System (DNS) servers (the link between the Windows Internet Naming Service--WINS--and DNS can be troublesome). You want to use the information as input into a homegrown network management tool. You want to back up the data, or you're just curious.

Problem Solved
DHCPCMD solves the text-dump problem. DHCPCMD is a command-line tool that lists active leases, creates new scopes, and modifies DHCP server parameters. I'll focus on the active lease listing function, because it's the most useful. The syntax looks like

dhcpcmd enumclients [-v] [-h]

Serveripaddress is the IP address of the DHCP server. You must use the server's IP address or a NetBIOS name (such as \JUBJUB); DHCPCMD cannot resolve DNS names. Scopeaddress is the network number of the DHCP scope. Look in the left pane of the DHCP Manager, and you'll see the network number under the server's name. (If you're not clear about what a network number is, see "IP Routing with NT," March 1996.) The DHCP Manager lets you use labels, such as basic scope, as the scope address, but DHCPCMD takes only the network number. If you use the -v option, DHCPCMD will give you a lot of information through long, descriptive messages. If you use the -h option, DHCPCMD will include hardware information about the machines with active leases.

Suppose you have a DHCP server named Numberman at IP address 200.200.100.7 that hands out leases from 200.200.100.10 through 200.200.100.67, and the network number of this scope is 200.200.100.0. You can ask the server to show you its active leases with either of the following commands:

dhcpcmd 200.200.100.7 enumclients 200.200.100.0

or

dhcpcmd umberman enumclients 200.200.100.0

DHCP's response might look like

1200.200.100.10MYIBM01/30/1998 02:32:41

2200.200.100.11DOODAD01/30/1998 02:47:41

Command successfully completed.

In this example, only two computers have IP addresses on Numberman, but DHCPCMD will dump IP addresses for as many computers as you have. You can redirect the output to capture the list of computers for future reference. To save the previous list, I type

dhcpcmd umberman enumclients 200.200.100.0 >saveit.txt

DHCPCMD will save the output to saveit.txt.

DHCPCMD is a cool tool that you're likely to find useful. Just remember that you must refer to DHCP servers by their IP address or NetBIOS name (not their DNS name), and you must refer to scopes by their network number (not their scope name). In addition, I found a limitation of DHCPCMD: I couldn't run the tool on a DHCP server from a workstation in a non-trusted domain, even though NT had authenticated me on the DHCP server with an account that the DHCP server recognized as an administrative account. Thus, a final rule: Run DHCPCMD from NT machines in trusted domains.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like