In my personal experience of using, I have different working environment, such as the company and home, the company requires fixed IP, and the home is the use of automatic access to IP, so I found this code on the Internet, and after their own changes, you can directly double-click the operation can be convenient to switch IP address.
Here the main use of Netsh commands, not too clear to Baidu to check, here is not to enumerate its usage, the specific code is as follows:
Fixed IP and Dns.bat
Copy Code code as follows:
@echo off
Cls
Color 0A
Echo *******************************************************************************
Echo is modifying the IP address and DNS server address, please wait patiently ...
Echo *******************************************************************************
cmd/c netsh interface ip set address name= ' Local area Connection ' source=static addr=192.168.1.136 mask=255.255.255.0 gat eway=192.168.1.1 gwmetric=1
cmd/c netsh interface ip set DNS name= "Local area Connection" Source=static addr=192.168.1.1
cmd/c netsh interface ip add DNS name= "local area Connection" addr=127.0.0.1 index=2
Ipconfig/all
Echo *******************************************************************************
Echo ok!! has been modified successfully! Please press any key to continue .....
Echo Thank you for your use! Cloud Small Fly production
Echo *******************************************************************************
Pause
Dynamic IP and Dns.bat
Copy Code code as follows:
@echo off
Cls
Color 0A
Echo *******************************************************************************
Echo is modifying the IP address and DNS server address, please wait patiently ...
Echo *******************************************************************************
netsh interface ip set address name= ' Local area Connection ' Source=dhcp
netsh interface ip delete dns ' local area Connection ' all
Ipconfig/flushdns
Ipconfig/all
Echo *******************************************************************************
Echo ok!! has been modified successfully! Please press any key to continue .....
Echo Thank you for your use! Cloud Small Fly production
Echo *******************************************************************************
Pause
The above two pieces of code, respectively, saved to a different bat file, you need to switch when you can double-click to run directly.
In addition, the static ARP binding gateway can also be added to the batch process, which can refer to the specific usage of the ARP command in my another article. For example:
Copy Code code as follows:
Arp-s 192.168.1.1 00-24-01-75-52-85
Automatically set IP address. bat
Copy Code code as follows:
Echo off
echo set IP address manually ....
Netsh interface IP Set Addr "Local Area Connection" Static 192.168.1.8 255.255.255.0 192.168.1.1 1
echo manually set DNS address ....
Netsh interface IP Set DNS "Local Area Connection" static 202.106.196.115 Primary
echo Manually sets the backup DNS address ....
Netsh interface IP Add DNS "Local Area Connection" 202.106.0.20
Echo set successfully your IP is 192.168.1.8, after pressing any key, you can use the intranet ...
Pause
Automatically obtain an IP address. bat
Copy Code code as follows:
Echo off
echo automatically gets IP address ....
netsh interface ip set address name = "Local Area Connection" Source = DHCP
echo automatically gets DNS server ....
netsh interface ip set dns name = "Local Area Connection" Source = DHCP
Echo automatically obtains IP success, press any key, you can use the extranet ...
Pause
Copy the corresponding code to the. bat file as needed.