Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

information from Windows dhcp

Posted on 2010-11-18
7
Medium Priority
?
379 Views
Last Modified: 2012-05-10
I need to fetch the current leases from a Windows dhcp server by a script. Or is a kind of dhcp query possible?
0
Comment
Question by:GeologyETH
7 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 34164307
You can use netsh dhcp server

netsh dhcp server dump

netsh dhcp server show all

then parse the output to the way you want.
0
 
LVL 59

Expert Comment

by:Darius Ghassem
ID: 34164317
0
 
LVL 6

Expert Comment

by:ipajones
ID: 34164335
Try this in your script:

netsh dhcp server \\dhcpservername show scope scope_name show clients

0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 7

Expert Comment

by:Dusan_Bajic
ID: 34164876
What ipajones suggested will work, but if you have more than one scope you can run this as a .bat and get them all at once:

For /F "skip=5 delims= " %%a IN ('netsh dhcp server \\dhcpservername show scope') DO (
      if not %%a == Total (if not %%a == Command netsh dhcp server \\dhcpservername scope %%a show clients >> leases.txt)
)
0
 

Author Comment

by:GeologyETH
ID: 34166660
Thanks for the answers. I tried "netsh server \\<server> scope x.y.z.c show clients", but this cmd doesn't include the client's name. I need the couple client's name + ip-no.
I modified the script dhcpcheckerv2.2 tow actual situation; it runs, but doesn't mail a result. Not sure what's wrong.
0
 

Author Comment

by:GeologyETH
ID: 34173401
The scripts works, but doesn't deliver the client's name + ip-no. Any other idea?
0
 
LVL 7

Accepted Solution

by:
Dusan_Bajic earned 2000 total points
ID: 34173491
just add option 1 at the end
...... show clients 1 >> leases.txt)
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question