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 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.
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
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 22.214.171.124 that hands out leases from 126.96.36.199 through 188.8.131.52, and the network number of this scope is 184.108.40.206. You can ask the server to show you its active leases with either of the following commands:
dhcpcmd 220.127.116.11 enumclients 18.104.22.168
dhcpcmd \\numberman enumclients 22.214.171.124
DHCP's response might look like
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 \\numberman enumclients 126.96.36.199 >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.