批处理全自动配置IP地址,网关,dns » 荒野无灯weblog

Keep It Simple, Stupid.

荒野无灯weblog

批处理全自动配置IP地址,网关,dns

@echo off
title "网络配置程序--by 荒野无灯 QQ:admin#ihacklog.com"
mode con: cols=80 lines=23
ECHO.
ECHO ==================Configurating, Please Wait==================
ECHO.
ECHO ==================Network Configuration Application================== > netcfg.log
color 3f
ECHO. 

::::::::::::::::::::::::::::::::::::::::::
:: 用户定义段
:: 如需自定义,请修改这里
::

:: 说明:
:: addr_name..........网络连接名称
:: addr_ip............IP地址
:: addr_mask..........子网掩码
:: addr_gateway.......网关
:: addr_dns_pri.......主DNS
:: addr_dns_sec.......副DNS

set addr_name="本地连接%n%"
set addr_ip=172.30.189.3
set addr_mask=255.255.0.0
set addr_gateway=172.30.189.254
set addr_dns_pri=61.234.254.5
set addr_dns_sec=61.234.254.6
::::::::::::::::::::::::::::::::::::::::::

echo addr_name=%addr_name% >> netcfg.log
echo addr_ip=%addr_ip% >> netcfg.log
echo addr_mask=%addr_mask% >> netcfg.log
echo addr_gateway=%addr_gateway% >> netcfg.log
echo addr_dns_pri=%addr_dns_pri% >> netcfg.log
echo addr_dns_sec=%addr_dns_sec% >> netcfg.log

:::::::::::::::::::::::::::::::::::::::
::设置ip, gateway, and mask
:: if ip=null

:IP
ECHO. Applying IP set... 
ECHO. Applying IP set... >> netcfg.log
IF DEFINED addr_ip (netsh interface ip set address name=%addr_name% source=static addr=%addr_ip% mask=%addr_mask% >>netcfg.log) else (netsh interface ip set address name=%addr_name% source=dhcp >> netcfg.log)

GOTO GATEWAY

:GATEWAY
ECHO. Applying gateway set... 
ECHO. Applying gateway set... >> netcfg.log
NETSH INTERFACE IP DELETE ADDR NAME=%addr_name% GATEWAY=ALL >> netcfg.log
IF DEFINED addr_gateway (NETSH INTERFACE IP ADD ADDR NAME=%addr_name% GATEWAY=%addr_gateway% GWMETRIC=1 >> netcfg.log)

GOTO DNS

 :D NS
ECHO. Applying DNS set... 
ECHO. Applying DNS set... >> netcfg.log
netsh interface ip delete dns name=%addr_name% addr=all >> netcfg.log
IF DEFINED addr_dns_pri (netsh interface ip add dns name=%addr_name% addr=%addr_dns_pri% index=1 >> netcfg.log)
IF DEFINED addr_dns_sec (netsh interface ip add dns name=%addr_name% addr=%addr_dns_sec% index=2 >> netcfg.log)
GOTO SHOW

:SHOW
ECHO. 
ECHO. 
ECHO. 
ECHO. Retult: ====================================================================
ECHO. Retult: ==================================================================== >> netcfg.log
IPCONFIG /ALL
IPCONFIG /ALL >> netcfg.log
pause 

Tagged in : dns,gateway,ip,netsh,bat,dos

All Comments (0)
Gravatar image
No Comments