
批處理修改網(wǎng)絡(luò)參數(shù)怎樣設(shè)置DNS和metric下面這坨是我弄的一個修改網(wǎng)絡(luò)參數(shù)的批,有幾個問題1.修改次要DNS該怎么弄2.修改DNS的時候總是會提示提供的DNS參數(shù)不正確,這是啥原因3.對metric怎么處理比較合理,現(xiàn)在是跳過這項,直接設(shè)成1
- @echo off
- :select_int
- cls
- set cnt=0
- echo 請選擇網(wǎng)絡(luò)接口
- echo.
- echo 0.退出
- for /f tokens=4,5 delims= %%i in ('netsh int ip sh int') do (
- if %%i==connectedcall :int_list %%j
- )
- echo.
- set /p s_int=選擇(1-%cnt%,0=退出):
- if %s_int%== goto select_int
- set tmp=0
- set delm=%tmp%
- :get_list_count
- if not %tmp%==%cnt% (
- call :get_lc
- goto get_list_count
- )
- for /f tokens=1 delims=%delm% %%a in ('echo %s_int:~0,1%') do (
- if not %%a== echo 輸入有誤 && pause>nul && goto select_int)
- if %s_int:~0,1%==0 goto :eof
- set chint=%s_int:~0,1%
- set/a cnt=0
- for /f tokens=4,5 delims= %%i in ('netsh int ip sh int') do (
- if %%i==connectedcall :int_list2 %%j
- )
- set newip=
- set newms=
- set newgw=
- set newdn=
- :show_int
- cls
- echo 網(wǎng)絡(luò)接口%c_int%的參數(shù)
- echo.
- echo 0.退出
- for /f tokens=3 delims=: %%i in ('netsh int ip sh addr %c_int%^|findstr IP 地址') do (echo 1.IP 地 址:%%i-%newip% && set ip=%%i)
- for /f tokens=4 delims=:) %%j in ('netsh int ip sh addr %c_int%^|findstr 子網(wǎng)前綴') do (echo 2.子網(wǎng)掩碼:%%j-%newms% && set ms=%%j)
- for /f tokens=2 delims=: %%k in ('netsh int ip sh addr %c_int%^|findstr 默認(rèn)網(wǎng)關(guān)') do (echo 3.網(wǎng)關(guān):%%k-%newgw% && set gw=%%k)
- for /f tokens=2 delims=: %%l in ('netsh int ip sh addr %c_int%^|findstr 網(wǎng)關(guān)躍點數(shù)') do (echo 4.躍 點 數(shù):%%l && set mr=1)
- for /f tokens=4 delims=: %%m in ('netsh int ip sh dns %c_int%^|findstr DNS 服務(wù)器') do (echo 5.主要 DNS:%%m-%newdn% && set dn=%%m)
- echo 6.確認(rèn)參數(shù)并退出
- echo.
- set /p cid=選擇對應(yīng)編號修改參數(shù)(1-5,0=不保存退出,6=保存修改并退出):
- if %cid%== goto show_int
- for /f tokens=1 delims=0123456 %%a in ('echo %cid:~0,1%') do (
- if not %%a== echo 輸入有誤 && pause>nul && goto show_int)
- if %cid:~0,1%==0 goto :eof
- if %cid:~0,1%==6 goto confimpara
- if %cid:~0,1%==4 goto show_int
- call :newpara %cid:~0,1%
- goto show_int
- :confimpara
- echo.
- echo.
- echo.
- if not %newip%== set ip=%newip%
- if not %newms%== set ms=%newms%
- if not %newgw%== set gw=%newgw%
- if not %newdn%== set dn=%newdn%
- echo 錯誤信息:(如無提示即正確)
- netsh int ip set addr %c_int% static %ip% %ms% %gw% %mr%
- netsh int ip set dns %c_int% static %dn% primary
- echo.
- echo.
- echo.
- pause
- goto :eof
- :newpara
- if %1==1 set str=IP地址
- if %1==2 set str=子網(wǎng)掩碼
- if %1==3 set str=網(wǎng)關(guān)
- if %1==5 set str=主DNS服務(wù)器地址
- set /p newp=請輸入新%str%:
- if %newp%== goto :eof
- for /f tokens=1 delims=0123456789. %%a in ('echo %newp%') do (
- if not %%a== echo 輸入有誤
- pause>nul
- set/a newp=
- goto :eof
- )
- for /f tokens=1,2,3,4,5 delims=. %%b in ('echo %newp%') do (
- if %%b lss 0 (echo 第一位小于0&&pause>nul&&set/a newp=)
- if %%b gtr 255 (echo 第一位大于255&&pause>nul&&set/a newp=)
- if %%c lss 0 (echo 第二位小于0&&pause>nul&&set/a newp=)
- if %%c gtr 255 (echo 第二位大于255&&pause>nul&&set/a newp=)
- if %%d lss 0 (echo 第三位小于0&&pause>nul&&set/a newp=)
- if %%d gtr 255 (echo 第三位大于255&&pause>nul&&set/a newp=)
- if %%e lss 0 (echo 第四位小于0&&pause>nul&&set/a newp=)
- if %%e gtr 255 (echo 第四位大于255&&pause>nul&&set/a newp=)
- if not %%f==(echo 輸入有誤&&pause>nul&&set/a newp=)
- )
- if %1==1 set newip=%newp%
- if %1==2 set newms=%newp%
- if %1==3 set newgw=%newp%
- if %1==5 set newdn=%newp%
- goto :eof
- :int_list
- set /a cnt+=1
- echo %cnt%.%1
- goto :eof
- :int_list2
- set /a cnt+=1
- if %cnt%==%chint% set c_int=%1
- goto :eof
- :get_lc
- set /a tmp+=1
- set delm=%delm%%tmp%
- goto :eof
- :eof
nclick="copycode($('code0'));">復(fù)制代碼