新建一个txt文件,进入后输入代码,先布置环境
@ECHO OFF
:begin
CLS
color 0a
GOTO MENU
:MENU
ECHO.
ECHO. =-=-=-=-=批处理菜单示例=-=-=-=-=
ECHO.
ECHO. 1 1.2
ECHO.
ECHO. 2 1.5
ECHO.
ECHO. 3 退 出
ECHO.
ECHO.
ECHO.
echo. 请输入选择项目的序号:
set /p ID=
if "%id%"=="1" goto cmd1
if "%id%"=="2" goto cmd2
IF "%id%"=="3" exit
PAUSE
之后是cmd1的代码
:cmd1
@echo off
rem eth
set eth="以太网"
rem ip
set ip=192.168.1.2
rem gw
set gw=192.168.1.1
rem netmasks
set netmasks=255.255.255.0
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 -all
echo…………………….
pause
goto begin
cmd2的代码
:cmd2
@echo off
rem eth
set eth="以太网"
rem ip
set ip=192.168.1.5
rem gw
set gw=192.168.1.1
rem netmasks
set netmasks=255.255.255.0
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 -all
echo…………………….
pause
goto begin
另存为ANSI格式

右键管理员启动后

按1和2即可修改成功
最后,为了方便使用,在首行添加代码来获取管理员权限
@echo off
cd /d "%~dp0"
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit
:Admin
现在,不需要右键管理员运行也可以使用了!
完整代码
@echo off
cd /d "%~dp0"
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit
:Admin
cls
@ECHO OFF
:begin
CLS
color 0a
GOTO MENU
:MENU
ECHO.
ECHO. =-=-=-=-=批处理菜单示例=-=-=-=-=
ECHO.
ECHO. 1 1.2
ECHO.
ECHO. 2 1.5
ECHO.
ECHO. 3 退 出
ECHO.
ECHO.
ECHO.
echo. 请输入选择项目的序号:
set /p ID=
if "%id%"=="1" goto cmd1
if "%id%"=="2" goto cmd2
IF "%id%"=="3" exit
PAUSE
:cmd1
@echo off
rem eth
set eth="以太网"
rem ip
set ip=192.168.1.2
rem gw
set gw=192.168.1.1
rem netmasks
set netmasks=255.255.255.0
echo 正在将本机gw更改到: %gw%
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 -all
echo…………………….
echo 成功将本机ip更改为%ip%!
pause
goto begin
:cmd2
@echo off
rem eth
set eth="以太网"
rem ip
set ip=192.168.1.5
rem gw
set gw=192.1681.1
rem netmasks
set netmasks=255.255.255.0
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 -all
echo…………………….
echo 成功将本机ip更改为%ip%!
pause
goto begin
未经允许不得转载:天府数据港官方信息博客 » 使用windows脚本,修改ip地址,子网掩码和网关
客官点个赞呗! (0)