批量绑定ipv4地址方法
以绑定192.168.1.192/26为例
先通过http://tool.520101.com/wangluo/ipjisuan/ 计算ip地址。
获取到第一个和最后一个可用ip尾数为193和254,以及掩码255.255.255.192,注意查看服务器上网卡网络连接名称,加入以下批处理脚本保存为ip.bat,然后直接运行即可。
@echo off
for /l %%a in (193,1,254) do netsh interface ip add address name="本地连接 2" addr=192.168.1.%%a mask=255.255.255.192
类似教程:https://blog.mydns.vip/1210.html
批量绑定ipv6方法
@echo off&setlocal enabledelayedexpansion color 3f ::判断外网网卡 for /f "tokens=1 delims=:" %%i in ('ipconfig /all ^| findstr "255.255.255.0 以太网适配器" ^| findstr /N "255.255.255.0"') do (set a=%%i) set /a n=%a%-1 set/a n-=1 if "%n%"=="0" (set "skip=") else (set "skip=skip=%n%") for /f "%skip% tokens=* delims=" %%i in ('ipconfig /all ^| findstr "255.255.255.0 以太网适配器"') do (set a=%%i&&goto:net) :net for /f "tokens=2,3 delims= " %%a in ("%a%") do (set network=%%a %%b) set network=%network:~0,-1% set network=%network::=% :start echo 1 单个添加ipv6地址 2 批量添加ipv6地址 3 查看ipv6地址 4 添加网关dns echo. set /p choice="请选择功能(输入数字1、2、3、4回车进入):" if not defined choice ( echo "不能输入空字符" goto start) if %choice% ==1 call :one if %choice% ==2 call :many if %choice% ==3 call :show if %choice% ==4 call :gate echo 不能输入除1、2、3、4之外其他字符! & goto start ::单次添加ipv6 :one echo. echo 1 添加单个ipv6地址 echo. echo 示例:240E:D9:E200:105:F645::B80回车即可添加,注意输入不要有空格 echo. set /p var="请输入ipv6地址:" if not defined var ( echo "ipv6地址不能为空" goto one) netsh interface ipv6 add address "%network%" %var% echo ipv6:%var% 添加完成 echo. ::判断网关是否添加 :verify for /f "tokens=1,2,3,4 delims=:" %%a in ("%var%") do (set a=%%a && set b=%%b && set c=%%c && set d=%%d && set iptmp=%%a:%%b:%%c:%%d::) ipconfig /all | findstr "默认网关" | findstr "%a%\:%b%\:%c%\:%d%\:\:1" >nul 2>nul if %errorlevel% ==1 ( netsh interface ipv6 add route ::/00 "%network%" %iptmp%1 echo 检查未配置网关,添加网关%iptmp%1 完成 ) set dns1=240e:56:4000:8000::69 set dns2=240C::6666 ipconfig /all | findstr "%dns1%" >nul 2>nul if %errorlevel% ==1 ( netsh interface ipv6 add dns "%network%" %dns1% netsh interface ipv6 add dns "%network%" %dns2% index=2 echo 检查未配置预设dns,添加首选dns:%dns1% 备用dns:%dns2% 完成 echo. goto start ) echo. goto start ::批量添加ipv6 :many echo. echo 2 批量添加ipv6地址 echo. echo 温馨提醒:服务器分配32个ipv6地址是连续的,输入起始和结束ipv6地址自动添加 echo 示例(输入不要有空格): echo 输入开始ipv6地址:240E:D9:E200:105:F645::B80回车 echo 输入结束ipv6地址:240E:D9:E200:105:F645::B9F回车 echo. set /p var="请输入开始ipv6地址: " if not defined var ( echo "ipv6地址不能为空" goto many) set /p var1="请输入结束ipv6地址: " if not defined var1 ( echo "ipv6地址不能为空" goto many) for /f "tokens=6 delims=:" %%a in ("%var%") do (set "num=%%a") set /a "mix=0x%num%" for /f "tokens=6 delims=:" %%a in ("%var1%") do (set "nummax=%%a") set /a "max=0x%nummax%" set /a num1=%max%-%mix% for /f "tokens=1,2,3,4,5 delims=:" %%a in ("%var%") do (set iptmp1=%%a:%%b:%%c:%%d:%%e::) set id=-1 set /a num2=%mix%-1 if %num1% equ 0 ( netsh interface ipv6 add address "%network%" %var% echo ipv6:%var% 添加完成 echo. goto start ) :loop set /a id+=1 set /a num2+=1 set/a s=%num2% set str=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ set "b=" :lp set /a "n=8189,m=0,r=0" for /l %%a in (1,1,14) do ( set /a "u=(n+m)/2" for %%i in (!u!) do if "!s:~%%i!" equ "" (set /a n=u) else set /a m=u ) for /l %%i in (0,1,%u%) do ( rem set/a "n=!s:~%%i,1!+(r*10),r=n&1,n>>=1" set/a "n=!s:~%%i,1!+(r*10),r=n%%16,n/=16" set v=!v!!n! ) set b=!str:~%r%,1!!b! if "!v:0=!" neq "" set s=!v!&set "v="&goto lp netsh interface ipv6 add address "%network%" %iptmp1%!b! echo ipv6:%iptmp1%!b! 添加完成 echo. if "%id%"=="%num1%" goto end goto loop :end echo. echo 批量添加ipv6添加完成 echo. goto verify goto start ::查看网卡配置 :show echo 3 查看网卡配置 echo. ipconfig | findstr "IPv6 地址" ::netsh interface ipv6 show address ::netsh interface ipv6 show route echo. goto start ::网关和dns配置 :gate echo 4 添加网关dns echo. echo 温馨提示:添加ipv6地址时脚本自动添加了网关和预设dns echo 仍要设置请输入 echo. set /p vara="ipv6网关地址:" set /p dns1="请输入ipv6首选dns地址:" set /p dns2="请输入ipv6备用dns地址:" netsh interface ipv6 set dns "%network%" source=static addr=none >nul 2>nul for /f "tokens=1,2,3,4 delims=:" %%a in ("%vara%") do (set iptmp=%%a:%%b:%%c:%%d::) netsh interface ipv6 add route ::/00 "%network%" %iptmp%1 echo 网关%iptmp%1 添加完成 netsh interface ipv6 add dns "%network%" %dns1% netsh interface ipv6 add dns "%network%" %dns2% index=2 echo 首选dns:%dns1% 添加完成 echo 备用dns:%dns2% 添加完成 echo. goto start
复制以上脚本保存为ip.bat,然后直接运行,根据提示添加。
» 本文链接地址:https://mydns.vip/4804.html
最新评论
麻烦发下检测工具
让我下载
非常好