We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Batch File: Monitor DHCP activities

Medium Priority
1,040 Views
Last Modified: 2012-05-11
Hi there,

I need to create a batch file to monitor our Windows Server 2003 DHCP server, and all changes are to be displayed within the DOS window.

Thanks for your help,
Rene
Comment
Watch Question

Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thanks Chris,

I'll look at it tomorrow.

Cheers,
Rene

Commented:
Here is a way to dump all the assigned DHCP ip addresses for all of your scopes with a single command from the command prompt:

for /f %i in ('netsh dhcp server MYDHCPSERVERNAME show scope ^|findstr "255.0"') do netsh dhcp server MYDHCPSERVERNAME scope %i show clients

Please note if you want to use this in a batch file you need to use two % not just one so it would be:

show-dhcp-clients.bat
================
for /f %%i in ('netsh dhcp server MYDHCPSERVERNAME show scope ^|findstr "255.0"') do netsh dhcp server MYDHCPSERVERNAME scope %%i show clients

Author

Commented:
@xylog,

The command line did not work for me.

So I tried: netsh dhcp server mydhcpservername show scope

And I got the an error saying that the command was not found: netsh ... scope

So I openned a DOS window on my XP computer:
Typed:
>netsh
>dhcp  = Command not found.

I openned a DOS window on my Domain Controller
Typed:
>netsh
>dhcp
>server MYDHCPSERVERNAME  =  COMMAND NOT FOUND
>show scope  =  LISTED ALL DHCP SCOPS BUT NOT THEIR CONTENTS

Thanks and cheers,
Rene
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Which OS version on each? I tend to test stuff on Win 7 / 2008 R2 which can mangle results as MS do so like to change things, including netsh.

Anyway, with the command above, you'd need to select the scope, then list the clients inside that scope. I've been meaning to write a decent PowerShell interface for DHCP, but time seems limited recently.

Chris

Author

Commented:
Correction:

On the D.C.

>server show scope  =  LISTED ALL DHCP SCOPS BUT NOT THEIR CONTENTS
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
The command is literal, show scope shows you the configured scopes, not leases or reservations within the scope.

Chris

Author

Commented:
@Chris-Dent

XP Pro and the D.C. is W.S. 2003

A command line would be preferable. I'll only use Power Shell if absolutly needed.

Thanks for your help,
Rene
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

NetSh is all you'll get really, it'll be a case of playing with the options inside. You're looking to enter the Scope context, then get the clients. I'm afraid I can't give you 2003 / XP specific syntax, I don't run either any more.

But, from where you are, it should be a case of:

scope <NetworkAddressOfYourScope>

Then take a look at the show options.

It's not a very good or consistent interface I'm afraid, but it really is the only one you'll get unless you go for exporting to a file in the DHCP MMC (if it even permits that).

Chris

Commented:
Did you try the command I posted above:

for /f %i in ('netsh dhcp server MYDHCPSERVERNAME show scope ^|findstr "255.0"') do netsh dhcp server MYDHCPSERVERNAME scope %i show clients

That will dump out all client leases for all scopes.

Author

Commented:
Yes I've tried it.
It's the MYDHCPSERVERNAME portion that bugs on my D.C.

(Yes I replace MYDHCPSERVERNAME with the name of my DHCP server  ;-)

So since you insisted, I'v played with it, removed it from the command line as:
for /f %i in ('netsh dhcp server show scope ^|findstr "255.0"') do netsh dhcp server scope %i show clients

This worked when running it on the domain controller (that is also the DNCP server) but now, I need to run it from my XP Pro computer.

Thanks

Author

Commented:
for /f %i in ('netsh dhcp server show scope ^|findstr "255.0"') do netsh dhcp server scope %i show clients
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Works on a remote W.S. 2003.

And what about the fact that the NETSH DHCP command is not available on my XP Pro PC?

Have any ideas?

Thanks,
Rene

Commented:
You can use psexec to run the command remotely:

psexec -U username \\MYDHCPSERVERNAME netsh dhcp server \\MYDHCPSERVERNAME show scope

What used to do was run a batch file as a scheduled task on the dhcp server every 15 minutes to dump all the client info to a text file that I could view on a webpage.

Author

Commented:
Works for me.

Thanks a million for your help!!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.