Yesterday I learned how to program and obtain the information of the local Nic. Today I learned how to modify the IP address of the local Nic. In fact, the principle is very simple, just call the doscommand with C ++. I have to say that the doscommand is too powerful. Of course I heard there is another method to modify the registry, but I have not tried it, so put the code that calls the DOS command to modify the local IP address. The compiling environment is still code: block 10.05.
# Include <iostream> <br/> # include <string> <br/> # include <cstdlib> <br/> # include <windows. h> </P> <p> using namespace STD; </P> <p> // set the command line </P> <p> string cmd = "netsh interface IP Set address name =/" Local Connection/"static "; </P> <p> int main () <br/> {<br/> string IPaddress = "202.2.2.3 "; // ip address <br/> string mask = "255.255.255.0"; // subnet mask <br/> cmd + = IPaddress + "" + mask; <br/> cout <CMD <Endl; <br/> system ("@ echo off"); <br/> System (CMD. c_str (); <br/> system ("@ echo on"); <br/> system ("ipconfig/all "); </P> <p> return 0; <br/>}< br/>
Running result:
Before modification:
After running the program: