Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


June 1998

DHCPCMD


RSS
Subscribe to Windows IT Pro | See More Internet Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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 <serveripaddress> enumclients <scopeaddress> [-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 \\numberman 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 \\numberman 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.

End of Article



Reader Comments
I'm currently using DHCPCMD to automate the configuration of several servers, I can't seem to enter two IPs for a subscope option such as DNS for instance...Does someone know how to ?

Michael November 21, 2002


using DHCPCMD you can get a list of IP's and NetBIOS name using the DHCP server. But what API call does this ? i.e like to write my own DHCPCMD in C.

Gavin Lyons August 28, 2003


I'm currently using DHCPCMD to automate the configuration of several servers, I can't seem to enter two IPs for a subscope option such as WINS for instance...Does someone know how to ?

JrMoreno June 22, 2004


I've been using this tool for years and am wanting to dig deeper. How can I add reservations and add options? I.e. option 067 boot file name. How can I look at a reservation and see an option?

murrayman October 28, 2004


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Related Events WinConnections and Microsoft® Exchange Connections

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement