Set IP address with DOS command

Please try to save these text below as a *.bat file, then excute it, you will be able to set the IP address on your local PC in a simply way:

==================== IP Address Configruation Batch Process Source ==========================

@echo off
title IP自动设置
MODE con: COLS=80 lines=30
color 0a

:main
cls

echo IP Manager Tool
echo.
echo 要把IP设置为公司用的IP 请按 1
echo 要把IP设置为自动获取 请按 2
echo 要退出 请按 3
echo.

set /p choice=          你的选择:

echo.

if "%choice%"=="1" goto ip1
if "%choice%"=="2" goto ip2
if "%choice%"=="3" goto end
if "%choice%"=="4" goto test

goto main

:ip1
echo  IP自动设置开始....
echo.

echo      正在设置IP, 子网掩码, 网关地址
netsh interface ip set address "本地连接" static 10.10.120.121 255.0.0.0 10.10.120.8
@rem 以上这句是设置IP为10.10.120.121 子网掩码为255.0.0.0 网关为10.10.120.8

echo      正在设置DNS服务器
netsh -c interface ip set dns name="本地连接" source=static addr=10.10.120.8 register=PRIMARY
@rem 以上这句为设置DNS为10.10.120.8

echo      正在设置备用DNS服务器
netsh -c interface ip add dns name="本地连接" addr=10.10.120.11
@rem 以上这句为设置备用DNS为10.10.120.8

echo      设置完成
echo.
 
CHOICE /C YN /M "退出请按 Y,返回菜单请按 N。"

if errorlevel 2 goto main
if errorlevel 1 goto end


:ip2
echo  IP自动设置开始....
echo.
echo  自动获取IP地址....
netsh interface ip set address name = "本地连接" source = dhcp
echo  自动获取DNS服务器....
netsh interface ip set dns name = "本地连接" source = dhcp

@rem 设置自动获取IP
echo      设置完成
echo. 
CHOICE /C YN /M "退出请按 Y,返回菜单请按 N。"

if errorlevel 2 goto main
if errorlevel 1 goto end

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

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

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

CHOICE /C YN /M "退出请按 Y,返回菜单请按 N。"

if errorlevel 2 goto main
if errorlevel 1 goto end

:end

posted @ 2011-08-23 14:51  C.Jun  阅读(609)  评论(0编辑  收藏  举报