Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know how to change the IP address of the system using this code. But this will change only the current connection.

public void setIP(string ip_address, string subnet_mask)
       {
           ListAllNetworkAdapters();

           ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
           ManagementObjectCollection objMOC = objMC.GetInstances();

           foreach (ManagementObject objMO in objMOC)
           {
               if ((bool)objMO["IPEnabled"])
               {
                   try
                   {
                       ManagementBaseObject setIP;
                       ManagementBaseObject newIP =
                           objMO.GetMethodParameters("EnableStatic");

                       newIP["IPAddress"] = new string[] { ip_address };
                       newIP["SubnetMask"] = new string[] { subnet_mask };

                       setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
                   }
                   catch (Exception)
                   {
                       throw;
                   }


               }
           }
       }


I Listed the multiple network adaptors using the code

C#
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
           {
               if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
               {
                   cmbAdaptors.Items.Add(ni.Name);

               }
           }

Now I want to change the IP address of each adaptor to a different IP address. I want to put IP address for WiFi and put a different IP to LAN cable connection.

How I can change the IPv4 address of selected network adaptor using code.
Posted
Updated 23-Feb-17 23:23pm
v3

1 solution

I think this article might help you, by classifying different network adapter and even profiling them for next use!
SwitchNetConfig - Laptop users, quickly switch network and proxy configuration in different places[^]
 
Share this answer
 
Comments
Arun Kumar K S 26-Oct-15 1:42am    
Thank you for your replay but that article didn't helped me to solve my issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900