473,581 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managing DHCP Servers using C# or another .net lang

Managing DHCP Servers using C#
They said it was impossible. It couldn't be done. But you can in fact
manage DHCP servers using C#. This includes creating and deleting
Scopes, SuperScopes, Reservations, Exclusions, Options and so forth.
Since the dll that is used was written several years ago by Microsoft,
you cannot manage things on the DNS tab when looking at a reservation
and few things such as that however it gives you main things you would
want to do. The DLL is also written to give you a snapshot view when
querying, which is fine for most C# applications.
Follow these 5 basic steps to get started:
1. Get the DHCPOBJS.DLL from the Windows 2000 Resource Kit
2. Create a COM+ Application for the DHCPOBJS.DLL
3. Convert the DHCPOBJS.DLL to a Common Language runtime assembly using
tlbimp
4. Copy the DHCPOBJECTS.DLL you created in step 3 to the bin directory
of your web application (or add a reference).
5. Setup permissions on your DHCP Servers
6. Start Coding

Get the DHCPOBJS.DLL from the Windows 2000 Resource Kit
Get out your trusty Windows 2000 Server Resource Kit books and break
out that CD in the back that contains all the utilities you thought you
would ever need. If that doesn't work try googling for "Windows
2000 Server Resource Kit" or "dhcpobjs.e xe" or
"dhcpobjs.e xe". Everything I've read in the newsgroups says that
this tool isn't supported by Microsoft, but then again that is there
standard disclaimer for all Windows 2000 resource kit tools.
Once you get the DHCPOBJS.EXE extract it. Along with the dll there is
a help file that gives a rough overview and some code usage in VBA. It
also includes the object model as shown in figure 1.A.

Figure 1.A
Create a COM+ Application for the DHCPOBJS.DLL
You could simply use regsvr32 to register the DLL, but since you want
to use it in IIS, it is necessary to place the dhcpobjs dll in a COM+
application so that you do not receive "access denied" errors from
your C# web application. If you have already registered this DLL for
any reason, unregister it using regsvr32 /u before creating the COM+
application.
Also once completed the dhcpobjs component can be called from IIS,
VBScript etc without any access denied or other authentication issues.
The COM+ application is given an "Identity" which it uses to
authenticate itself. The information for these steps has been modified
from the justftp.dll COM+ application creation steps located at
http://www.easterndigitalsoftware.co...alkthrough.htm .
IMPORTANT NOTE: For Windows 2003 only, be sure to follow the extra step
required for component access checking changes after step 18.
(This extra step is not necessary for Windows 2000.)
1. Create a directory called "DHCPOBJS" in "C:\Program Files\ComPlus
Applications".
i.e. "C:\Program Files\ComPlus Applications\DH CPOBJS". You could
use any directory, but this will help organize things.
2. Copy the dhcpobjs.dll file into this directory.
3. Start the Component Services GUI from the start menu: Start /
Programs / Administrative Tools / Component Services (Or, Control Panel
/ Administrative Tools / Component Services) or run dcomcnfg.
4. Expand "My Computer" as shown below. Select COM+ Applications and
right click. Select New / Application.

5. The COM+ App. install dialog pops up. Click Next.
6. Click "Create an empty application".

7. Enter the name DHCPOBJS and ensure "Server application" is selected
for the Activation Type. Click Next.

8. At the Identity dialog, select "This user" and enter a valid domain
or local computer account username and password. This account will be
used in Step 5 of the master steps at the beginning of this document. I
recommend something like "DHCPOBJS Administrator" and for it to be
a domain account.

A local administrative user account is recommended but I have found it
works without. (For Windows 2003 only, the "Network Service" account
can be used, however this account will only have "user" group rights).
Click Next. NOTE: At this point, the credentials entered are checked.
If you receive an error, the credentials are invalid for some reason.
9. No "roles" are modified. Simply click Next on the Add Application
Roles dialog.
NOTE: Windows 2000 does not prompt with these dialog boxes.
AGAIN NOTE: Windows 2000 does not prompt with these dialog boxes.
10. Click Next on the Add Users to Roles Dialog box.
11. Click Finish to create the empty COM+ application.
12. The empty DHCPOBJS 'package' should now be showing in the COM+
Applications tree. We will now add the DHCPOBJS component to this
application.
Expand the DHCPOBJS entry and select components.
13. Right click Components and select New Component.
14. The COM+ Component install dialog pops up. Click Next.
15. Click "Install new components".
16. Select DHCPOBJS.dll by browsing to the directory you put the DLL in
step 2. Double click it, (or select it and click "Open").
17. A Install new components dialog should open. Click Next to install
and register the DHCPOBJS component.
18. Click Finish to end the component install process for DHCPOBJS.
NOTE: The above procedure correctly registers DHCPOBJS in the registry.
There is no need to give the manual regsvr32 command.

IMPORTANT NOTE FOR Windows 2003:
Default security settings will restrict access to DHCPOBJS. Access
denied errors will occur unless this extra step is completed.

Perform this extra step on Windows 2003 installations of DHCPOBJS in
COM+.
Open Component Services, locate DHCPOBJS and right click on DHOBJS.
Select properties to open the property dialog.
Select the security Tab and uncheck the "Enforce access checks for this
application" checkbox in the Authorization section.
DHCPOBJS can now be called by IIS, scripts and applications without
"access denied" errors.
(There is no need to perform this step for Windows 2000.)
This completes the installation of DHCPOBJS as a managed COM+
application.

Convert the DHCPOBJS.DLL to a Common Language runtime assembly using
tlbimp

The Type Library Importer converts the type definitions found within a
COM type library into equivalent definitions in a common language
runtime assembly. More information on the Type Library Importer can we
found at http://msdn2.microsoft.com/en-us/lib...sx(VS.80).aspx
.. What that means it you have to make a wrapper around the dhcpobjs.dll
so that .net will recognize your COM+ application you just created. I
have not tried this in anything older than Microsoft Visual Studio
2005.
1. Find the tlbimp.exe file usually located at C:\Program
Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\ tlb.
2. Run tlbimp.exe dhcpobjs.dll and it will create DhcpObjects.dll

Copy the DHCPOBJECTS.DLL you created in step 3 to the bin directory of
your web application (or add a reference).
This is pretty self-explanatory, but it creates a reference in your
web application.

Setup permissions on your DHCP Servers
In order to create objects you will be required to have the account
you used when setting up the COM+ application in step 2 to be in the
DHCP Administrators group on the Local machine. Putting that account in
the Domain Group DHCP Administrators will not be enough. It would give
that account permissions to authorize DHCP Servers in AD, but it will
not allow creation of things on the DHCP servers such as reservations
and scopes.
I would recommend creating an AD group similar to "DHCP Management
Administrators" and putting that group in the "DHCP
Administrators" local group found on each DHCP server. Then put your
account used to setup your COM+ application in step 2 in the DHCP
Management Administrators group. You may have to restart your IIS
application and your COM+ application after getting this all done
before it will let you create objects on the DHCP server. You will get
an error saying unable to create object (different from access denied)
if your permissions are not correct.

Start Coding
I don't have a lot of samples to give you but if you read over the
DHCP Objects documentation and look at the VBA examples you should be
able to get a pretty good idea of what is required.
Be sure to add the "using DhcpObjects;" at the top of your page.
To create a reservation:
DhcpObjects.Man ager dhcpmgr = new DhcpObjects.Man ager();
DhcpObjects.Ser ver dhcpsrvr;
dhcpsrvr = dhcpmgr.Servers .Connect("1.1.1 .1");
// You could also used a scope number such as [1] instead of an IP
address
lblRecordNameRe sult.Text = dhcpsrvr.Scopes["1.1.1.0"].Name.ToString( );

Reservation DHCPReservation =
dhcpsrvr.Scopes["10.1.1.0"].Reservations.C reateNew();

DHCPReservation .Name = "TestReservatio n.yourdomain.co m";
DHCPReservation .UniqueID = "0010000000 08";
DHCPReservation .Address = "1.1.1.3";
DHCPReservation .Comment = "This is the description";
DHCPReservation .Update();
dhcpsrvr.Discon nect();
To get the Name of a IP Reservation your could use:
strReservationR esults =
dhcpsrvr.Scopes["1.1.1.0"].Reservations["1.1.1.3";].Name.ToString( );
This should get your started. The objection model shows most of the
things you can do. Have fun!

Dec 8 '06 #1
0 12329

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
13704
by: Richard D. Ford | last post by:
Does anyone know if VB has an exposed API that can be used to query DHCP for current address leases? I have seen threads that discuss DHCPObj.dll and have successfully used it. However, this only exposed the server's configuration, not the current address leases. I was also able to track down an interface that is exposed to C, but 1.)...
3
3295
by: jmd.msdn | last post by:
Hello. Is it possible to obtain programmatically, with .net 2.0 + C# + Active Directory or P/Invoke, a list of the authorized current DHCP servers in a forest/domain ? And, if the above question can be solved, is it also possible to manage the DHCP servers (list, add, remove scopes, ...) ? Thank you.
2
3046
by: WhatHappend | last post by:
I have converted a .Net 1.0 application to .Net 2.0 and the web service invocations have delay of around 10seconds on each intial access. After the first access subsequent access are fast (After a whild of inactivity the next access will be slow agian). Changing the client to static IP address instead of DHCP makes the initial access about 1...
5
7633
by: Richard | last post by:
Hello, I'm working on an application to allow our network team to use a small application to make DHCP reservations on our Microsoft DHCP Server. The problem is you have to use P/Invoke to do it, and from what I've found on the web and in this newsgroup is that it's not easy, however I believe it can/has been done. At the moment I'm...
1
11117
by: Screenbert | last post by:
After finding nothing anywhere in google I am posting this so everyone can benefit by it. The formating is not pretty since I copied it from my word document, but you should benefit by it. Managing DHCP Servers using C# They said it was impossible. It couldn't be done. But you can in fact manage DHCP servers using C#. This includes...
0
1258
by: Ant000 | last post by:
Hello, Is it possible to manage a DHCP Server with an ASP page (vbscript) using dhcpsapi.dll or another DHCP API ? How could I do this? thanks!
1
5119
by: yannifan | last post by:
Hi This is my first post and am a newbie to network programming. My currrent assignment is concerned with DHCP client server programming and need some help with that. I need to request two IP addresses on the client side from the server. I have a single LAN card and the request is sent from client on the same LAN card. The first request...
7
3093
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
Quick q: If I open a socket on my computer and eventualy the dhcp changes the address of my computer, what happens? Will it drop the connection? Thanks in advance for any help on the topic.
2
2705
by: raaman rai | last post by:
Friends, as i raised this issue earlier but i couldn't get any answer. Well i have a very small LAN in my office with a server (Windows Server 2003). I have configured my server with DHCP. I have two NICs in the server computer, one configured for my internal LAN and another for internet from ISP. The second adapter was added recently. Well, my...
0
7876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.