The Netsh command IP settings

Source: Internet
Author: User
Tags dns2 get ip

Batch processing, VBS implementation automatically set the IP, default gateway, DNS, WINS, ie proxy code, the required friends can refer to the following

Because the company has a colleague responsible for Dalian, Shenyang Two cities, often in the two places to walk, to each city, they have to manually change the corresponding network configuration, and in the field when staying is hotel, hotel Internet is automatically get IP, but also the network settings canceled, really troublesome! So I remembered to write a batch processing! To solve this problem! The main command used is netsh.
The first method is to set the network configuration of the two places first, then export, and so on, and then separately imported.
1. Export the existing configuration to D:\dalian.txt:
Netsh-c interface Dump >d:\dalian.txt
2. Import the previously exported d:\dalian.txt file:
Netsh-f D:\dalian.txt
This method is a bit slower to execute than the following method.


Ii. Second method
Syntax format:
1. Set IP, Gateway
netsh interface ip set address name= "Local Area Connection" Static IP address subnet Mask gateway IP gateway metric to set

2. Set the primary DNS, WINS
netsh interface ip set dns/wins name= "Local Area Connection" Static DNS address to set Register=primary

2. Setting up alternate DNS, WINS
netsh interface ip add dns/wins name= "Local Area Connection" to set the DNS address index=2

4 getting DNS automatically
netsh interface ip set address name= "Local Area Connection" Source=dhcp

5 Automatic access to alternate DNS
netsh interface ip set DNS name= "Local Area Connection" Source=dhcp

The specific configuration is as follows:
1, hotel. bat
Copy the code code as follows:
@echo off
Echo cancels the specified network configuration, please wait a moment ....
Echo.
Echo is setting up the IP address automatically, please wait a moment ...
netsh interface ip set address name= "Local Area Connection" Source=dhcp
echo is setting up auto-get DNS, please wait a moment ...
netsh interface ip set DNS name= "Local Area Connection" Source=dhcp
echo Setup is complete!
2, Dalian. bat
Copy the code code as follows:
@echo off
Echo starts setting up the Dalian network address!
Echo is setting up Dalian IP, please wait ...
netsh interface ip set address name= "Local Area Connection" Source=static addr=10.15.100.86 mask=255.255.0.0
Echo is setting up Dalian Gateway, please wait ...
netsh interface ip set address name= "Local Area Connection" gateway=10.15.0.253 gwmetric=1
Echo is setting up Dalian Master DNS, please wait ...
netsh interface ip set DNS name= "Local Area Connection" Source=static addr=10.15.0.1 register=primary
Echo is setting up Dalian standby DNS, please wait ...
netsh interface ip add DNS name= "Local Area Connection" addr=10.100.1.2 index=2
Echo is setting up Dalian Master wins, please wait a moment ...
netsh interface ip set wins name= "Local Area Connection" Source=static addr=10.15.0.1
Echo is setting up Dalian standby wins, please wait ...
netsh interface ip add wins name= "Local Area Connection" addr=10.100.1.2 index=2
echo Setup is complete!
3, Shenyang. bat
Copy the code code as follows:
@echo off
Echo starts setting up the Shenyang network address!
Echo is setting up Shenyang IP, please wait ...
netsh interface ip set address name= "Local Area Connection" Source=static addr=10.16.100.86 mask=255.255.0.0
Echo is setting up the Shenyang Gateway, please wait a moment ...
netsh interface ip set address name= "Local Area Connection" gateway=10.16.0.253 gwmetric=1
Echo is setting up Shenyang Master DNS, please wait ...
netsh interface ip set DNS name= "Local Area Connection" Source=static addr=10.16.0.1 register=primary
Echo is setting up Shenyang standby DNS, please wait ...
netsh interface ip add DNS name= "Local Area Connection" addr=10.100.1.2 index=2
Echo is setting up Shenyang Master wins, please wait ...
netsh interface ip set wins name= "Local Area Connection" Source=static addr=10.16.0.1
Echo is setting up Shenyang standby wins, please wait ...
netsh interface ip add wins name= "Local Area Connection" addr=10.100.1.2 index=2
echo Setup is complete!



Third, you can also use the variable in batch processing! such as Dalian. BAT can be written in the following ways:
Copy the code code as follows:
@ echo off
REM Setting variables
Set nic= Local Area Connection
REM//Can be changed according to your needs,
Set addr=10.15.100.86
Set mask=255.255.0.0
Set gway=10.15.0.253
Set dns1=10.15.0.1
Set dns2=10.100.1.2
Set wins1=10.15.0.1
Set wins2=10.100.1.2
REM//above IP address, subnet mask, gateway, preferred DNS, alternate DNS, preferred wins, alternate wins
Echo------------------------------------------------------
Echo is in the Dalian IP settings, please wait a moment
REM//Can be changed according to your needs
Echo. IP address =%addr%
Echo. Subnet mask =%mask%
netsh interface ip set address name=%nic% source=static addr=%addr% mask=%mask% >nul
Echo. Gateway =%gway%
netsh interface ip set address name=%nic% gateway=%gway% gwmetric=1 >nul
Echo. Preferred DNS =%dns1%
netsh interface ip set DNS name=%nic% source=static addr=%dns1% register=primary >nul
Echo. Alternate DNS =%dns2%
netsh interface ip add DNS name=%nic% addr=%dns2% index=2 >nul
Echo. Preferred wins =%wins1%
netsh interface ip set wins name=%nic% source=static addr=%wins1% register=primary >nul
Echo. Alternate wins =%wins2%
netsh interface ip add wins name=%nic% addr=%wins2% index=2 >nul
Echo------------------------------------------------------
echo IP Settings complete!

The Netsh command IP settings

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.