批处理设置IP

@ECHO off

netsh interface ip set address name="本地连接" source=static addr=10.160.13.55 mask=255.255.255.0

echo IP和子网掩码设置完成

netsh interface ip set address name="本地连接" gateway=10.160.13.254 gwmetric=0

echo 网关设置完成........

netsh interface ip set dns name="本地连接" source=static addr=10.1.3.5 register=PRIMARY

echo DNS1设置完成........
netsh interface ip add dns name="本地连接" addr=10.210.62.12
echo DNS2设置完成........
netsh interface ip set wins name="本地连接" source=static addr=none
 
-----------------------------------------------------------------------------
批处理设置IP及DNS——复习一下BAT
方法一:
 
echo off
echo 修改[本地连接]IP......

netsh interface IP set address "本地连接" static 138.8.8.111 255.255.255.0 138.8.8.1 1

echo 修改[本地连接]DNS......
netsh interface IP set dns "本地连接" static addr=202.96.128.86
 
把上面的复制到笔记本,另存为 修改IP.bat 的文件
 
138.8.8.111 IP地址
255.255.255.0 子网掩码
138.8.8.1 1 默认网关
 
202.96.128.86 DNS
 
下面就是自动获取IP
 
echo off
echo 修改IP,自动获取IP...
netsh interface ip set address name="本地连接" source=dhcp
echo 修改DNS,自动获取DNS...
netsh interface ip set dns name="本地连接" source=dhcp
 
 
方法二:
 
@echo off
mode con cols=50 lines=20
title IP地址设定工具
color 3f
cls
echo.
echo.

echo       IP地址切换程序

echo   ----------------------------

echo.

echo   更换为20的IP,请按 [h]

echo.  

echo   更换为51的IP,请按 [g]

echo.

echo   按其他任意键退出 程序。

echo.

echo   ----------------------------

echo                    -----By: LuTian
echo.
echo.
echo.
set ch=

set /p ch= 请根据上面提示输入:

IF /I '%ch:~0,1%'=='h' GOTO Family
IF /I '%ch:~0,1%'=='g' GOTO Office
IF /I '%Choice:~0,1%'=='' GOTO Ex
exit
 
::下面的程序是设置IP等为动态获取。
:Family
cls
echo.
echo.
echo.
echo.
echo.
echo            正在更换为20的IP,请稍侯... ...

netsh interface ip set address name="本地连接" source=static addr=192.168.20.250 mask=255.255.255.0

::设置IP为192.168.20.250 ,子网掩码为255.255.255.0

 

netsh interface ip set address name="本地连接" gateway=192.168.20.254 gwmetric=0

::设置网关为192.168.20.254
 

netsh interface ip set dns name="本地连接" source=static addr=168.95.1.1 register=PRIMARY

::设置首选DNS为168.95.1.1
 

netsh interface ip add dns name="本地连接" addr=202.96.128.143 index=2

::设置备用DNS为202.96.128.143
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo             感谢使用,按任意键退出...
pause>nul
Exit
 
::下面的程序是设置IP等为静态手工输入。
:Office
cls
echo.
echo.
echo.
echo.
echo.
echo            正在更换为51的IP,请稍侯... ...

netsh interface ip set address name="本地连接" source=static addr=192.168.51.29 mask=255.255.255.0

::设置IP为192.168.50.50 ,子网掩码为255.255.255.0

 

netsh interface ip set address name="本地连接" gateway=192.168.51.254 gwmetric=0

::设置网关为192.168.51.254
 

netsh interface ip set dns name="本地连接" source=static addr=168.95.1.1 register=PRIMARY

::设置首选DNS为168.95.1.1
 

netsh interface ip add dns name="本地连接" addr=202.96.128.143 index=2

::设置备用DNS为202.96.128.143
 
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo             感谢使用,按任意键退出...
pause>nul
Exit
:Ex
echo
exit
 
 
 
方法三
 
用记事本打开修改位置如下{分别为以下[0.0.0.0]的位置}
IP地址(netsh interface ip set address name="本地连接" static addr=192.168.1.0)
 

子网掩码(mask=255.255.255.0 >nul)

 

默认网关(netsh interface ip set address name="本地连接" gateway=192.168.1.1 gwmetric=0 >nul)

 

首选DNS服务器(netsh interface ip set dns name="本地连接" source=static addr=0.0.0.0 register=PRIMARY >nul

 

备用DNS服务器(netsh interface ip add dns name="本地连接" addr=0.0.0.0 index=2 >nul

 
 
 
另外做IP.bat的方法是复制分隔线以下内容,新建一个文本文件,打开后将内容复制进去后,按上方内容将IP修改后,另存为自己设名***.bat即可
 
--------------------------------------------------------------------
@echo off
title=自动切换ip地址
color 0A
 
rem *************** 自动切换ip地址程序 ***************

rem    主要用于在计算所内部ip和宿舍ip自动切换

rem **************************************************

 
set find=%SystemRoot%\System32\find.exe

set config=%SystemRoot%\System32\ipconfig.exe

 
goto :start
 
 
:start
cls
echo                      ╭─────────────╮

echo       ╭──────┤    IP地址自动设置程序    ├──────╮

echo       │            ╰─────────────╯            │

echo       本程序能为您自动或手动设置合适的IP,网关及DNS          │

echo       │                                   Design By: 浪子回头│

echo       ╰───────────────────────────╯

echo.

echo        1. 设置成计算所静态IP

echo        2. 设置成宿舍动态ip

echo        Q. 退出

echo       ==========================================================

set type=
set /P type=       请选择: [1],[2]或[3]?

if /I "%type%"=="1" goto :goictstatic

if /I "%type%"=="2" goto :godormdyn

if /I "%type%"=="Q" goto :end

goto :start
 
 
:goictstatic
echo.

echo       将IP地址设置成 192.168.1.0

echo       子网掩码设置成 255.255.255.0

echo       网关地址设置成 192.168.1.0

echo       DNS:202.96.128.166

echo.

echo       正在设置IP地址及子网掩码

netsh interface ip set address name="本地连接" source=static addr=192.168.1.0 mask=255.255.255.0 >nul

echo       正在设置默认网关地址

netsh interface ip set address name="本地连接" gateway=192.168.1.0 gwmetric=0 >nul

echo       正在设置DNS

netsh interface ip set dns name="本地连接" source=static addr=202.96.128.166 register=PRIMARY >nul

netsh interface ip add dns name="本地连接" addr=0.0.0.0 index=2 >nul

goto :showip
 
:godormdyn
echo.
echo 正在设置动态IP地址,请稍候!
netsh interface ip set address name="本地连接" source=dhcp >nul
echo 正在设置动态DNS地址,请稍候!
netsh interface ip set dns name="本地连接" source=dhcp>nul
goto :showip
 
:showip
cls
ipconfig/all
 
::netsh int ip show address
 
echo.

echo    按任一键退出程序!

pause >nul
 
:end
echo
///////////////////////////////////////////////////////////////////////////////
 批处理设置IP 收藏
经常在多个地方上网,需要来回切换IP地址,十分不便,可以考虑编写批处理程序轻松切换IP地址。
 
IP地址可以通过netsh命令来设置,具体参数可以通过在cmd窗口下,执行netsh/? 命令来查看,下面进行简单说明:
 
一. 设置IP
 
a 设置自动获取IP命令
 
netsh interface ip set address name="本地连接" source=dhcp
 
b 设置固定IP命令
 

netsh interface ip set address name="本地连接" source=static addr=192.168.1.2 mask=255.255.255.0 gateway=192.168.1.1 gwmetric=auto

 
参数说明:
 
1.name:网络连接名称,一般为“本地连接”。你可以在“控制面板”->“网络连接”中看到。
 
2.source:获取IP的途径。动态获取,则为dhcp,手动设置,则为static。
 
3.addr:要设置的IP地址。
 
4.mask:子网掩码。
 
5.gateway:网关地址。
 
6.gwmetric:网关跃点数,可以设置为整型数值,也可以设置为“自动”:auto。
 
二.设置DNS
 
a 自动获取DNS
netsh interface ip set dns name="本地连接" source=dhcp
b 手动设置单个DNS

netsh interface ip set dns name="本地连接" source=static addr=210.52.149.2 register=primary

c 手动设置多个DNS

netsh interface ip set dns name="本地连接" addr=202.106.0.133 index=2

 
 
参数说明:
 
1.name:网络连接名称,一般为“本地连接”。你可以在“控制面板”->“网络连接”中看到。
 
2.source:获取IP的途径。动态获取,则为dhcp,手动设置,则为static。
 
3.addr:要设置的IP地址。
 
4.register:可以取值none, primary, both,分别表示
 
a.none: 禁用动态 DNS 注册。
 
b.primary: 只在主 DNS 后缀下注册。
 
c.both: 在主 DNS 后缀下注册,也在特定连接后缀下注册。
 
5.index:设置的DNS的顺序号。
 
设置固定IP批处理程序setFixedIP.bat, 代码如下:
 
@echo off

netsh interface ip set address name="本地连接" source=static addr=192.168.81.164 mask=255.255.255.0 gateway=192.168.81.1 gwmetric=auto

netsh interface ip set dns name="本地连接" source=static addr=192.168.80.21 register=primary

pause
exit
 
设置自动获取IP批处理程序setAutoIP.bat, 代码如下:
 
@echo off
netsh interface ip set address name="本地连接" source=dhcp
netsh interface ip set dns name="本地连接" source=dhcp
pause
exit
===============================================================================
@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如"本地连接"
set eth="本地连接"
rem ip //ip 为你想更改的IP
set ip=192.168.4.23
rem gw //gw 为网关地址
set gw=192.168.4.1
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.192
 
echo 正在将本机IP更改到: %ip%
rem

if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul

if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul

echo.........................
echo 检查当前本机IP:
ipconfig
echo.........................
echo 成功将本机IP更改为%ip%!
pause
close
////////////////////////////////////////////////////////////////////////////
经常进行自动ip和固定ip更改的用户,可以以下批处理,轻松实现自动ip和固定ip的更改。
 
一、设置自动ip
 

echo   设置开始自动IP,请稍等....

echo.

echo   正在自动获取IP地址....

netsh interface ip set address name = "本地连接" source = dhcp

echo 正在自动获取DNS ,请稍等......
netsh interface ip set dns "本地连接" source = dhcp
echo 设置完成!
 
 
二、设置固定ip
 
@echo off
echo 开始设置本机网络地址!
 
echo 正在设置本机IP ,请稍等......

netsh interface ip set address "本地连接" source = static addr = 192.168.1.3 mask=255.255.255.0

echo 正在设置本机网关,请稍等......

netsh interface ip set address "本地连接" gateway = 192.168.1.1 gwmetric =1

echo 正在设置本机DNS ,请稍等......

netsh interface ip set dns "本地连接" source = static addr = 211.98.2.4

echo 正在设置备用DNS ,请稍等......
netsh interface ip add dns "本地连接" addr=211.98.4.1
echo 设置完成!
/////////////////////////////////////////////////////////////////////////////
 

@ echo offrem 设置变量set Nic=本地连接 rem //可以根据你的需要更改,set Add=192.168.1.177echo ------------------------------------------------------echo 对于不连入局域网的ADSL用户,建议填写IP地址,

echo 以避免开机进入桌面后因网卡搜索IP地址造成的反应迟钝现象.
echo 本批处理帮助你快速将网卡ip设置为 %add%

echo ------------------------------------------------------

echo 正在设置ip,请稍等几秒....
rem //可以根据你的需要更改

netsh interface ip set address name=%Nic% source=static addr=%add% mask=255.255.255.0

echo 自动填写ip为 %add% 完成!

echo ------------------------------------------------------

pause >nul

猜你喜欢

转载自debugbb.iteye.com/blog/1423903