回复 3# 如你是我
这个是可以选择版本,只有一个网卡连网时,直接设置IP。当有多个网卡都连网时,可以选择给哪个网卡设置IP。- @echo off
- title IP设置
- mode con lines=7 cols=50
- setlocal enabledelayedexpansion
- color a
-
- set mask=255.255.255.0
- set DNS1=192.168.255.100
- set DNS2=192.168.255.101
- set isIP=false
- set "gateway="
- set "online="
- set "tips="
- set "s="
-
- :input_ip
- cls
- echo.&echo.
- set /p ip=%s%%s%请输入ip地址(如10.10.10.200):
- call :check_ip
- if "%isIP%" == "false" cls &echo.&echo.&echo.&echo %s%%s%IP地址格式不正确,按任意键返回重新输入! & pause >nul & goto input_ip
-
- for /f "delims=" %%i in ('ipconfig^|find "以太网"') do (
- set name=%%i
- set name=!name:~7,-1!
- for /f "delims=" %%i in ('netsh interface show interface "!name!" ^| find "已连接"') do set "online=!online! ^"!name!^""
- )
-
- for %%i in (!online!) do (
- set /a c+=1
- set "lan!c!=%%i"
- )
-
- if !c! == 1 call :set_ip !lan1! & goto :eof
-
- :choose
- set /a c+=5
- mode con lines=!c! cols=50
- cls
- echo.&echo %s%已连网的网卡:
- for %%i in (!online!) do (set /a n+=1&echo %s%%s%!n!.%%~i)
- echo.
- set /p choose=%s%请选择给哪个网卡设置IP地址:
- if "%choose%" == "" set "n=" & goto :choose
- if not defined lan%choose% set "n=" & goto :choose
- call :set_ip !lan%choose%!
-
- :check_ip
- if "%ip%" == "" set "isIP=false" & exit /b
- for /f "tokens=1-5 delims=." %%i in ("%ip%") do (
- if "%ip:~-1%" == "." set "isIP=false" & exit /b
- if "%%m" neq "" set "isIP=false" & exit /b
- if %%i leq 0 set "isIP=false" & exit /b
- if %%i gtr 252 set "isIP=false" & exit /b
- if %%j leq 0 set "isIP=false" & exit /b
- if %%j gtr 252 set "isIP=false" & exit /b
- if %%k leq 0 set "isIP=false" & exit /b
- if %%k gtr 252 set "isIP=false" & exit /b
- if %%l leq 1 set "isIP=false" & exit /b
- if %%l gtr 252 set "isIP=false" & exit /b
- set "gateway=%%i.%%j.%%k.254"
- set "isIP=true" & exit /b
- )
-
- :set_ip
- netsh interface ipv4 set address "%~1" static %ip% %mask% %gateway% 1 >nul
- netsh interface ipv4 add dns "%~1" %DNS1% index=1 >nul
- netsh interface ipv4 add dns "%~1" %DNS2% index=2 >nul
- cls&echo.&echo.&echo %s%%s%%s%%s%IP设置完成,按任意键退出! & pause >nul & goto :eof
复制代码
|