Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Change IP configuration using C++

Change IP configuration using C++

This sample illustrates how to programmatically change an IP address for a specific network adapter on your machine. This program also demonstrates how to retrieve existing network adapter IP configuration information using Win32 APIs.

IP configurations can be changed for a specific network adapter by using the AddIpAddress() and DeleteIpAddress() Ip Helper API functions. These functions require you to understand adapter index numbers and IP context numbers. In Windows, every network adapter has a unique index ID and every IP address has a unique context ID. Adapter index IDs and IP context numbers can be retrieved using the GetAdaptersInfo() IP Helper function. This program features a list option that displays current network adapter configuration information by showing all adapters index numbers and IP address context numbers associated with their corresponding network adaptors.

To execute this application, simply build the application using the Visual C++ (Version 5 SP 3 or better) Nmake.exe program generation facility. An ipchange.exe program should result. You can use any other C++ Compiler on windows.

Execute the ipchange.exe with the following parameters:

Ipchange.exe [ -l ] [ -a -n -i -m ] [ -d -c]

C++ For Dummies 7th Edition
Unlock the world of programming with C++ for Dummies – the perfect beginner’s guide to mastering C++ with ease and confidence!
View on Amazon

  1. -l List adapter index IDs and IP Address context ID information
  2. -a Add IP Address option
  3. -d Delete IP Address option
  4. -i IP Address to specify with -a option
  5. -m Subnet Mask to specify with -a option
  6. -c IP context ID for an existing IP address -n Index ID of an existing network
    adapter

Author: Jim Ohlund 21-Apr-98

About The Author

M. Saqib

Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.