[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 wujunkai 于 2020-4-6 18:27 编辑

回复 1# wwdzcdb


    还可以继续化简,等我有空。。。。
  1. @echo off & setlocal enabledelayedexpansion
  2. title I P修改小工具  Ver 1.0 【 污、克里里 】
  3. mode con: cols=64 lines=45 & color 0b
  4. for %%i in ("IP[0]=0","IP[1]=1","IP[2]=2","IP[3]=3","IP[4]=5","IP[5]=6","IP[6]=9","IP[7]=10","IP[8]=99","IP[9]=100") do set %%i
  5. :loop
  6.     cls
  7.     echo=
  8.     echo     ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
  9.     echo     ※                                                    ※
  10.     echo     ※           I P 修 改 小 工 具 v 1.0                 ※
  11.     echo     ※                                                    ※
  12.     echo     ※                                                    ※
  13.     echo     ※      「A」-   自   动   获   取   IP               ※
  14.     echo     ※                                                    ※
  15.     echo     ※      「0」  —→ 192 . 168 .   0 . 1               ※
  16.     echo     ※                                                    ※
  17.     echo     ※      「1」  —→ 192 . 168 .   1 . 1               ※
  18.     echo     ※                                                    ※
  19.     echo     ※      「2」  —→ 192 . 168 .   2 . 1               ※
  20.     echo     ※                                                    ※
  21.     echo     ※      「3」  —→ 192 . 168 .   3 . 1               ※
  22.     echo     ※                                                    ※
  23.     echo     ※      「4」  —→ 192 . 168 .   5 . 1               ※
  24.     echo     ※                                                    ※
  25.     echo     ※      「5」  —→ 192 . 168 .   6 . 1               ※
  26.     echo     ※                                                    ※
  27.     echo     ※      「6」  —→ 192 . 168 .   9 . 1               ※
  28.     echo     ※                                                    ※
  29.     echo     ※      「7」  —→ 192 . 168 .  10 . 1               ※
  30.     echo     ※                                                    ※
  31.     echo     ※      「8」  —→ 192 . 168 .  99 . 1               ※
  32.     echo     ※                                                    ※
  33.     echo     ※      「9」  —→ 192 . 168 . 100 . 1               ※
  34.     echo     ※                                                    ※
  35.     echo     ※      「S」-   手    动    输    入                 ※
  36.     echo     ※                                                    ※
  37.     echo     ※      「D」-   D   N   S   修    改                 ※
  38.     echo     ※                                                    ※
  39.     echo     ※      「I」-   I     P     修    改                 ※
  40.     echo     ※                                                    ※
  41.     echo     ※      「W」-   网    关    修    改                 ※
  42.     echo     ※                                                    ※
  43.     echo     ※      「R」-   重    启    网    卡                 ※
  44.     echo     ※                                                    ※
  45.     echo     ※      「Z」-   退    出    程    序                 ※
  46.     echo     ※                                                    ※
  47.     echo     ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
  48.     echo=
  49.     echo=
  50.     set /P ST="请输入序号:"
  51.     if /I "%ST%"=="A" call:setupA
  52.     if /I "%ST%"=="0" call:setup 0
  53.     if /I "%ST%"=="1" call:setup 1
  54.     if /I "%ST%"=="2" call:setup 2
  55.     if /I "%ST%"=="3" call:setup 3
  56.     if /I "%ST%"=="4" call:setup 4
  57.     if /I "%ST%"=="5" call:setup 5
  58.     if /I "%ST%"=="6" call:setup 6
  59.     if /I "%ST%"=="7" call:setup 7
  60.     if /I "%ST%"=="8" call:setup 8
  61.     if /I "%ST%"=="9" call:setup 9
  62.     if /I "%ST%"=="S" call:setupS
  63.     if /I "%ST%"=="D" call:setupD
  64.     if /I "%ST%"=="I" call:setupI
  65.     if /I "%ST%"=="W" call:setupW
  66.     if /i "%ST%"=="R" goto:rebootnet
  67.     if /i "%ST%"=="Z" goto:END
  68. goto:loop
  69. REM 新IP地址/前缀=Newip
  70. REM 设置子网掩码=Netmask
  71. REM 设置网关=Gateway
  72. REM 设置DNS Sever1=Dns1
  73. REM 设置DNS Sever2=Dns2
  74. :show
  75.     set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  76.     echo=
  77.     set/p=    <nul&%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%
  78.     echo    100%%
  79.     call:endl 5
  80.     echo              -------------------------------------
  81.     echo                成功设置本地连接IP地址和DNS
  82.     echo=
  83.     echo                当前 IP 地址:%Newip%
  84.     echo                当前子网掩码:%Netmask%  
  85.     echo                当前默认网关:%Gateway%
  86.     echo                当前首选 DNS:%Dns1%
  87.     echo                当前备用 DNS:%Dns2%   
  88.     echo              -------------------------------------
  89.     call:endl 8
  90. goto:eof
  91. :setupA
  92.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do     set %%A
  93.     echo NetConnectionID="%NetConnectionID%"
  94.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do     set %%A
  95.     echo index="%index%"
  96.     wmic nicconfig where index="%index%" call enabledhcp
  97.     wmic nicconfig where index="%index%" call setDNSServerSearchOrder()
  98.     netsh interface set interface "%NetConnectionID%" disabled
  99.     netsh interface set interface "%NetConnectionID%" enable
  100.     cls
  101.     set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  102.     echo=
  103.     set/p=    <nul&%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%
  104.     echo    100%%
  105.     call:endl 5
  106.     echo              -------------------------------------
  107.     echo                    自动获取IP地址成功!
  108.     echo              -------------------------------------
  109.     call:endl 8
  110.     pause
  111. goto:loop
  112. :setup
  113.     set "Newip=192.168.!IP[%~1]!.2"
  114.     set "Gateway=192.168.!IP[%~1]!.1"
  115.     set "Netmask=255.255.255.0"
  116.     set "Dns1=223.5.5.5"
  117.     set "Dns2=223.6.6.6"
  118.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do     set %%A
  119.     echo NetConnectionID="%NetConnectionID%"
  120.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do     set %%A
  121.     echo index="%index%"
  122.     wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  123.     wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  124.     wmic nicconfig where index="%index%" call setDNSServerSearchOrder("%Dns1%","%Dns2%")
  125.     wmic nicconfig where index="%index%" call setTcpipNetbios 2
  126.     netsh interface set interface "%NetConnectionID%" disabled
  127.     netsh interface set interface "%NetConnectionID%" enable
  128.     cls
  129.     call:show
  130.     pause
  131. goto:loop
  132. :setupS
  133.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do     set %%A
  134.     echo NetConnectionID="%NetConnectionID%"
  135.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do     set %%A
  136.     echo index="%index%"
  137.     cls
  138.     echo=
  139.     echo       ******手动设置本地连接IP地址,输入完成请回车确定******
  140.     echo=
  141.     echo=
  142.     set /p Newip="请输入 IP 地址:"
  143.     echo=
  144.     set "Netmask=255.255.255.0"
  145.     echo=
  146.     set /p Gateway="请输入默认网关:"
  147.     echo=
  148.     set "Dns1=223.5.5.5"
  149.     set "Dns2=223.6.6.6"
  150.     wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  151.     wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  152.     wmic nicconfig where index="%index%" call setDNSServerSearchOrder("%Dns1%","%Dns2%")
  153.     wmic nicconfig where index="%index%" call setTcpipNetbios 2
  154.     netsh interface set interface "%NetConnectionID%" disabled
  155.     netsh interface set interface "%NetConnectionID%" enable
  156.     cls
  157.     call:show
  158.     pause
  159. goto:loop
  160. :setupD
  161.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do     set %%A
  162.     echo NetConnectionID="%NetConnectionID%"
  163.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do     set %%A
  164.     echo index="%index%"
  165.     cls
  166.     echo=
  167.     echo       ******手动设置DNS地址,输入完成请回车确定******
  168.     echo=
  169.     echo=
  170.     set /p Dns1="请输入 首选DNS 地址:"
  171.     echo=
  172.     set /p Dns2="请输入 备用DNS 地址:"
  173.     wmic nicconfig where index="%index%" call setDNSServerSearchOrder("%Dns1%","%Dns2%")
  174.     wmic nicconfig where index="%index%" call setTcpipNetbios 2
  175.     netsh interface set interface "%NetConnectionID%" disabled
  176.     netsh interface set interface "%NetConnectionID%" enable
  177.     cls
  178.     set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  179.     echo=
  180.     set/p=    <nul&%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%
  181.     echo    100%%
  182.     call:endl 5
  183.     echo              -------------------------------------
  184.     echo                   D N S 修 改 完 成 !
  185.     echo=
  186.     echo                当前首选 DNS:%Dns1%
  187.     echo                当前备用 DNS:%Dns2%   
  188.     echo              -------------------------------------
  189.     call:endl 8
  190.     pause
  191. goto:loop
  192. :setupI
  193.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do     set %%A
  194.     echo NetConnectionID="%NetConnectionID%"
  195.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do     set %%A
  196.     echo index="%index%"
  197.     cls
  198.     echo=
  199.     echo       ******手动设置IP地址,输入完成请回车确定******
  200.     echo=
  201.     echo=
  202.     set /p Newip="请输入 IP 地址:"
  203.     echo=
  204.     set "Netmask=255.255.255.0"
  205.     wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  206.     wmic nicconfig where index="%index%" call setTcpipNetbios 2
  207.     netsh interface set interface "%NetConnectionID%" disabled
  208.     netsh interface set interface "%NetConnectionID%" enable
  209.     cls
  210.     set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  211.     echo=
  212.     set/p=    <nul&%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%
  213.     echo    100%%
  214.     call:endl 5
  215.     echo              -------------------------------------
  216.     echo                    I  P  修 改 完 成 !
  217.     echo=
  218.     echo                当前 IP 地址:%Newip%
  219.     echo                当前子网掩码:%Netmask%  
  220.     echo              -------------------------------------
  221.     call:endl 8
  222.     pause
  223. goto:loop
  224. :setupW
  225.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do     set %%A
  226.     echo NetConnectionID="%NetConnectionID%"
  227.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do     set %%A
  228.     echo index="%index%"
  229.     cls
  230.     echo=
  231.     echo       ******手动设置网关地址,输入完成请回车确定******
  232.     echo=
  233.     echo=
  234.     set /p Gateway="请输入默认网关:"
  235.     wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  236.     netsh interface set interface "%NetConnectionID%" disabled
  237.     netsh interface set interface "%NetConnectionID%" enable
  238.     cls
  239.     set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  240.     echo=
  241.     set/p=    <nul&%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%
  242.     echo    100%%
  243.     call:endl 5
  244.     echo              -------------------------------------
  245.     echo                   网 关 修 改 完 成 !
  246.     echo=
  247.     echo                当前网关地址:%Gateway%
  248.     echo              -------------------------------------
  249.     call:endl 8
  250.     pause
  251. goto:loop
  252. :rebootnet
  253.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do     set %%A
  254.     echo NetConnectionID="%NetConnectionID%"
  255.     for /f "tokens=*" %%A in ('    wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do     set %%A
  256.     echo index="%index%"
  257.     ping -n 3 127.1>nul
  258.     netsh interface set interface "%NetConnectionID%" disabled
  259.     netsh interface set interface "%NetConnectionID%" enable
  260.     cls
  261.     set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  262.     echo=
  263.     set/p=    <nul&%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a%
  264.     echo    100%%
  265.     call:endl 5
  266.     echo              -------------------------------------
  267.     echo                        网卡重启成功!
  268.     echo              -------------------------------------
  269.     call:endl 8
  270.     pause
  271. goto:loop
  272. :endl
  273.     for /L %%a in (1,1,%~1) do echo=
  274. goto:eof
  275. :end
  276.     endlocal
  277.     ping -n 3 127.1>nul
  278.     exit
  279. goto:eof
复制代码

TOP

回复 3# wwdzcdb


    已优化在二楼
    强烈建议使用call来代替goto。。。鬼知道我检查变量为什么传不过去用了多久

TOP

返回列表