How Windows 7 quickly switches IP scripts

Source: Internet
Author: User
Tags dns2 goto switches

I use dynamic IP at home, in the company to use fixed IP, so often need to switch back and forth IP settings, very troublesome! Today is unbearable, I put together a script to ease the trouble of switching IP back and forth! I'm afraid I have forgotten.

[Plain]

@echo off

REM//Set Variable

Set name= "Local Area Connection"

REM//The following property values can be changed as needed

Set addr=172.16.18.184

Set mask=255.255.255.0

Set gateway=172.16.18.254

Set dns1=172.16.17.1

Set dns2=8.8.8.8

REM//The above properties are IP address, subnet mask, gateway, preferred DNS, alternate DNS

Echo currently available actions are:

Echo 1 is set to static IP

Echo 2 is set to dynamic IP

Echo 3 exits

echo Please select rear carriage return:

set/p operate=

If%operate%==1 Goto 1

If%operate%==2 Goto 2

If%operate%==3 Goto 3

: 1

echo is setting static IP, please wait ...

REM//Can be changed according to your needs

echo IP address =%addr%

echo mask =%mask%

echo Gateway =%gateway%

netsh interface ipv4 set address name=%name% source=static addr=%addr% mask=%mask% gateway=%gateway% gwmetric=0 >nul

echo Preferred DNS =%dns1%

netsh interface ipv4 set DNS name=%name% source=static addr=%dns1% register=primary >nul

echo Alternate DNS =%dns2%

netsh interface ipv4 add DNS name=%name% addr=%dns2% index=2 >nul

echo static IP is set!

Pause

Goto 3

: 2

Echo is setting up dynamic IP, please wait ...

ECHO is automatically getting IP addresses from DHCP ...

netsh interface ip set address "Local Area Connection" DHCP

ECHO is automatically getting DNS addresses from DHCP ...

netsh interface ip set DNS "Local Area Connection" DHCP

echo Dynamic IP has been set!

Pause

Goto 3

: 3

Exit

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.