by any chance do u have some sample scripts for DHCP server
Main Topics
Browse All TopicsHi,
Is there a way to match mach adress of machines that have been leased ip to a mach adress database and invoke a script to release if not found in database.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Okay, so...
You can do this with NetSh:
NetSh dhcp server scope 10.0.0.0 show clients
Where 10.0.0.0 would be replaced by the scope you're using. If you're unsure what that is, this command lists them:
NetSh dhcp server show scope
You can delete leases using:
NetSh dhcp server scope 10.0.0.0 delete lease <LeaseIP>
Bear in mind here that deleting the lease will not prevent the client using the IP, this is no help as a measure to prevent unauthorised access. You'd better have Conflict Detection enabled if you're deleting leases without booting the client off the network.
If those issues are not a problem in this scenario, all that's left is wrapping a script around this to compare client leases to entries in the database.
Chris
If you're going for a more serious approach you should look at the DHCP API (or at least consider it), it's pretty well documented, although most of the nicer functionality isn't present until Windows 2008 R2.
http://msdn.microsoft.com/
More than enough available to do this though.
Using that in C# isn't so easy in my experience, everything uses Pointers, you'd have to permit Unsafe code. P/Invoke wrappers in C++ may be more appropriate, Marshalling some of the structures it returns is hard work in C# anyway (although it's possible that's due to my lack of experience with C# :)).
Anyway, the API is all NetSh is using, so don't feel constrained by scripting options if you can program this.
If you're sticking with a script called from we'd look at wrapping a text parser around the NetSh commands. That could match up the MAC addresses up. The IP Address and MAC are all returned by "show clients", I've attached an example of the output below (the MAC below is not modified to mask identity).
As you can see, it's rather messy, but not impossible to work with.
Finally, do note that you do not have to be local to the DHCP server to execute this command. Server names are an optional parameter of the "server" command. e.g.
netsh dhcp server \\SomeServer scope 10.0.0.0 show clients
Chris
You'd have to act as a Firewall, sitting between the network layer and the DHCP service, catching and handling broadcast requests for addresses from clients. I couldn't tell you how to do that I'm afraid.
Have you considered or looked at Network Access Protection that MS shipped with Windows 2008 Server?
Chris
Business Accounts
Answer for Membership
by: vikingtechnologiesPosted on 2009-09-15 at 23:01:25ID: 25342329
The only way i can think of is to make a script that runs with crontab every minut parse the "arp -n -a" and try to match with leased file.