标签:network pre 活动 网络连接 show tle got goto 网卡名称
@echo off
MODE con: COLS=80 lines=30
color 0b
title 自动IP By L
echo =====================
echo 自动IP By L
echo =====================
rem eth //eth 为网卡名称
echo 1.检测活动网卡...
rem 获取网络连接名称
@(for /f "tokens=3*" %%a in (‘netsh interface show interface^|more +2‘) do @echo,%%b)>"network.txt"
set j=0
for /f "tokens=*" %%i in (network.txt) do (
set /a j+=1
set con!j!=%%i
call set eth=%%con!j!%%
)
echo 当前活动网卡名称为:%eth%
set ipduan=149.32.49
rem gw //网关
set gw=%ipduan%.1
rem netmasks //子网掩码
set netmasks=255.255.255.0
rem 最大和最小IP地址
set MAXID=205
set MINID=5
echo 2.检查ID配置...
set j=0
for /f "tokens=*" %%i in (nowid.txt) do (
set /a j+=1
set con!j!=%%i
call set oldid=%%con!j!%%
)
if %oldid% LSS %MINID% (
echo 检查nowid.txt文件,ID:%oldid%不能小于%MINID%
goto changeerror)
echo 3.生成下一个ip地址...
set j=0
for /f "tokens=*" %%i in (nowid.txt) do (
set /a j+=1
set con!j!=%%i
call set id=%%con!j!%%
)
echo --------
echo 上一个编号为:%id%
echo 上一个ip地址为:%ipduan%.%id%
echo --------
set /a newid=%id%+1
if %newid% GTR %MAXID% (
echo IP段分配已达上限:%ipduan%.%MAXID%!请重新修改nowid.txt文件或检查IP地址
goto changeerror
) else (
echo %newid% > nowid.txt
echo 下一个编号为:%newid%
)
rem ip //ip 为你想更改的IP
set ip=%ipduan%.%newid%
echo 下一个ip地址:%ip%
echo 下一个ip地址网关:%gw%
echo 下一个ip地址掩码:%netmasks%
echo --------
echo 4.本机IP更改: %ip%
rem
netsh interface ipv4 set address %eth% static %ip% %netmasks% %gw%
rem >nul
echo.
echo 5.验证当前本机IP:
ipconfig -all >ipconfig.txt
type ipconfig.txt | find "%ip%" && goto success
:changeerror
echo 修改失败,请手动分配IP地址!
goto :end
:success
echo 修改成功
goto :end
:end
pause
echo.
标签:network pre 活动 网络连接 show tle got goto 网卡名称
原文地址:http://blog.51cto.com/13959448/2348855