Connect and Obtain IP address from DHCP

Posted on 2008-11-11
Last Modified: 2012-05-05
I am writing an application, which get a list of all network interfaces, with their IP address, MAC address and other info.
The interfaces which are connected with internet have obviously IP addresses. For example, My WLAN interface has IP address. For other interfaces, for example if I plug in a 3G card, it gets IP address when I click the CONNECT button on the software came with this card.
I dont want to use that Software to connect my 3G card and get IP address. Rather I want to enable that interface and get IP address from DHCP server programmatically in C++.
In simplest words I want my network card / adapter should be connected and be assigned IP address using C++.
Note: I am using Windows Vista.
Waiting for reply.
Question by:thisisazam
    1 Comment
    LVL 2

    Accepted Solution

    How about calling the command line tools "netsh" and "ipconfig" shipped with Windows? You can do this from your C++ program.
    Here is an example how to change the IP address assignment to DHCP (replace "MyConnection" by the name of your network - see Windows Control Panel):

    netsh interface ip set address name="MyConnection" source=dhcp

    To reassign the IP address via DHCP after this call:

    ipconfig /renew "MyConnection"

    Also the command line tool DevCon ( might help you to enable/disable network adapters in the Windows device manager.

    Attention: You need real admin rights to do this. On Vista with UAC enabled you need to launch the command line tools with elevation (e.g via ShellExecuteEx or your application already has an according manifest and already runs with real admin rights, see

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now