IP地址自動設置的批處理

@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.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章