Reputation: 41
How to change the IP address of a computer in Windows? Is there any available API?
Using AddIPAddress function, I have added the IP address and the newly IP address is successfully showing in the network connection details but failed to change in the tcp/ip table .So please suggest some way out.
Upvotes: 2
Views: 2946
Reputation: 970
To change IP and default gateway:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "netsh int ip set address \"local area connection\" static 192.168.0.101 255.255.255.0 192.168.0.254 1 ";
process.StartInfo = startInfo;
process.Start();
Upvotes: 1
Reputation: 681
Please look here if you want to change the setting from the command line (can be scripted). Or you might want to use Powershell using this example.
Upvotes: 0
Reputation: 114
Quick google search to find this link. Dont know if its what you're looking for.
Upvotes: 0
Reputation: 221997
Try EnableStatic and SetGateways of WMIObject Win32_NetworkAdapterConfiguration. The methods allows to configure the computer to use specific static IP address.
To tell the trust, one needn't set some static IP address in the most cases. One gets IP address from DHCP. One can use IpReleaseAddress and IpRenewAddress of iphlpapi in the case. I should remark that there is undocumented function SetAdapterIpAddress
exported by IpHlpApi.dll
, but I think that the usage of documented WMI method EnableStatic
is better.
Upvotes: 4