[Network programming/C ++] modifying the IP address of the Local Machine

Source: Internet
Author: User

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:

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.