---
title: "win7批处理设置IP"
author: "dayone"
date: "2010-03-31T08:38:09Z"
tags: ["C", "C#", "C++"]
categories: ["操作系统"]
slug: "win7-ip"
draft: false
lastmod: "2010-03-31T08:38:09Z"
id: 628821
url: "https://dayone.iteye.com/blog/628821"
---

将分割线以下的内容保存为xxxx.bat文件，然后在win7下右键选中该文件，选择“以管理员身份运行（A）”然后按提示操作。

 -----------------------------------分割线-------------------------------------

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

:main  
cls

echo 按提示操作  
echo.  
echo (1)要把IP设置为company的IP 请按数字 1 再按回车键  
echo (2)要把IP设置为自动获取 请按数字 2 再按回车键  
echo (3)要退出 请按 3 再按回车键  
echo.  
@rem 上一句是空一行

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及子网掩码  
cmd /c netsh interface ip set address name="本地连接" source=static addr=**192.168.0.136** mask=**255.255.255.0** gateway=192.100.3.11 gwmetric=1  
echo 正在设置DNS服务器  
cmd /c netsh interface ip set dns name="本地连接" source=static addr=**221.121.1.47** register=PRIMARY  
@rem 以上这句为设置DNS  
echo 正在设置DNS服务器  
cmd /c netsh interface ip add dns name="本地连接" addr=**221.121.1.38**  
@rem 以上这句为设置DNS  
echo 设置完成

pause  
exit

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 设置完成

pause  
exit

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