Link to home
Start Free TrialLog in
Avatar of MiSheps
MiShepsFlag for United States of America

asked on

C# - Release IP of specific adapter, and then renew (via DHCP) IP of that same adapter (after various tests run of course)

Greetings Experts,

Ok... here is the problem that I need to resolve.

have built code in my app to find specific information about all of the installed adapters, which includes:
1) IP address
2) Adapter Description
3) MAC address of adapter.

Now, what I need to be able to do, is:

Step 1) Specify a given adapter, release the IP address which is assigned to it (assigned by DHCP)
Step 2) Run some various tests that I'm working on building (network communication tests)
Step 3) Specify the given adapter and renew the IP for that adapter via DHCP.

Factors to keep in mind:

1) This will be utilized on machines with as many as 3 network interfaces (2 physical and 1 virtual)
2) I need to be able to release & Renew ALL IP info for the specified adapter. (including IP, Mask, DNS, etc)

Thanks in advance for any code examples that I could learn from!
Avatar of Blackninja2007
Blackninja2007

you could make a command line call to

ipconfig/release
&
ipconfig/renew
Avatar of MiSheps

ASKER


I would prefer not to use a basic windows function. I would rather do this programatically if possible, using a WMI if necessary such as ReleaseDHCPLease and RenewDHCPLease.

Though I don't know how to accomplish this.

Experts? Your help please!
ASKER CERTIFIED SOLUTION
Avatar of MiSheps
MiSheps
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MiSheps

ASKER

For the fun of it, I decided to build a stand alone application for the IP release and renew just to further learn C#.

You can download the full project in c# at the link below if you want to have a look at the code and let me know what you think.

Thanks.

http://www.mishepsbasement.com/Programming/DotNet/DragonIPReleaseAndRenew.rar


IPReleaseRenew-01.JPG
IPReleaseRenew-03.JPG
Your code looks good to me.

Using the WMI is really the only way to go as there are no 100% managed solutions yet.

Well done.

Jake