标题: [网络连接] 大佬帮忙精简优化IP小工具BAT代码 [打印本页]
作者: wwdzcdb 时间: 2020-4-5 11:33 标题: 大佬帮忙精简优化IP小工具BAT代码
自己写了个IP小工具 代码有些累赘 相同代码太多 请大佬帮忙优化精简- @echo off
- title I P修改小工具 Ver 1.0 【 污、克里里 】
- mode con: cols=64 lines=45 & color 0b
- :loop
- CLS
- @echo.
- @echo ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
- @echo ※ ※
- @echo ※ I P 修 改 小 工 具 v 1.0 ※
- @echo ※ ※
- @echo ※ ※
- @echo ※ 「A」- 自 动 获 取 IP ※
- @echo ※ ※
- @echo ※ 「0」 —→ 192 . 168 . 0 . 1 ※
- @echo ※ ※
- @echo ※ 「1」 —→ 192 . 168 . 1 . 1 ※
- @echo ※ ※
- @echo ※ 「2」 —→ 192 . 168 . 2 . 1 ※
- @echo ※ ※
- @echo ※ 「3」 —→ 192 . 168 . 3 . 1 ※
- @echo ※ ※
- @echo ※ 「4」 —→ 192 . 168 . 5 . 1 ※
- @echo ※ ※
- @echo ※ 「5」 —→ 192 . 168 . 6 . 1 ※
- @echo ※ ※
- @echo ※ 「6」 —→ 192 . 168 . 9 . 1 ※
- @echo ※ ※
- @echo ※ 「7」 —→ 192 . 168 . 10 . 1 ※
- @echo ※ ※
- @echo ※ 「8」 —→ 192 . 168 . 99 . 1 ※
- @echo ※ ※
- @echo ※ 「9」 —→ 192 . 168 . 100 . 1 ※
- @echo ※ ※
- @echo ※ 「S」- 手 动 输 入 ※
- @echo ※ ※
- @echo ※ 「D」- D N S 修 改 ※
- @echo ※ ※
- @echo ※ 「I」- I P 修 改 ※
- @echo ※ ※
- @echo ※ 「W」- 网 关 修 改 ※
- @echo ※ ※
- @echo ※ 「R」- 重 启 网 卡 ※
- @echo ※ ※
- @echo ※ 「Z」- 退 出 程 序 ※
- @echo ※ ※
- @echo ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
- @echo.
- @echo.
-
- @ SET /P ST="请输入序号:"
- echo.
- if /I "%ST%"=="A" goto setupA
- if /I "%ST%"=="0" goto setup0
- if /I "%ST%"=="1" goto setup1
- if /I "%ST%"=="2" goto setup2
- if /I "%ST%"=="3" goto setup3
- if /I "%ST%"=="4" goto setup4
- if /I "%ST%"=="5" goto setup5
- if /I "%ST%"=="6" goto setup6
- if /I "%ST%"=="7" goto setup7
- if /I "%ST%"=="8" goto setup8
- if /I "%ST%"=="9" goto setup9
- if /I "%ST%"=="S" goto setupS
- if /I "%ST%"=="D" goto setupD
- if /I "%ST%"=="I" goto setupI
- if /I "%ST%"=="W" goto setupW
- if /i "%ST%"=="R" goto rebootnet
- if /i "%ST%"=="Z" goto END
- goto loop
-
- REM 新IP地址/前缀=Newip
- REM 设置子网掩码=Netmask
- REM 设置网关=Gateway
- REM 设置DNS Sever1=Dns1
- REM 设置DNS Sever2=Dns2
-
- :setupA
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enabledhcp
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder()
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 自动获取IP地址成功!
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
- :setup0
- set "Newip=192.168.0.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.0.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup1
- set "Newip=192.168.1.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.1.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup2
- set "Newip=192.168.2.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.2.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup3
- set "Newip=192.168.3.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.3.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup4
- set "Newip=192.168.5.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.5.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup5
- set "Newip=192.168.6.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.6.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup6
- set "Newip=192.168.9.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.9.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup7
- set "Newip=192.168.10.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.10.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup8
- set "Newip=192.168.99.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.99.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setup9
- set "Newip=192.168.100.2"
- set "Netmask=255.255.255.0"
- set "Gateway=192.168.100.1"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setupS
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- @echo.
- @echo ******手动设置本地连接IP地址,输入完成请回车确定******
- @echo.
- @echo.
- set /p Newip="请输入 IP 地址:"
- @echo.
- set "Netmask=255.255.255.0"
- @echo.
- set /p Gateway="请输入默认网关:"
- @echo.
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 成功设置本地连接IP地址和DNS
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo 当前默认网关:%Gateway%
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setupD
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- @echo.
- @echo ******手动设置DNS地址,输入完成请回车确定******
- @echo.
- @echo.
- set /p Dns1="请输入 首选DNS 地址:"
- @echo.
- set /p Dns2="请输入 备用DNS 地址:"
-
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo D N S 修 改 完 成 !
- @echo.
- @echo 当前首选 DNS:%Dns1%
- @echo 当前备用 DNS:%Dns2%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setupI
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- @echo.
- @echo ******手动设置IP地址,输入完成请回车确定******
- @echo.
- @echo.
- set /p Newip="请输入 IP 地址:"
- @echo.
- set "Netmask=255.255.255.0"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo I P 修 改 完 成 !
- @echo.
- @echo 当前 IP 地址:%Newip%
- @echo 当前子网掩码:%Netmask%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :setupW
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- @echo.
- @echo ******手动设置网关地址,输入完成请回车确定******
- @echo.
- @echo.
- set /p Gateway="请输入默认网关:"
-
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 网 关 修 改 完 成 !
- @echo.
- @echo 当前网关地址:%Gateway%
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
- :rebootnet
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- ping -n 3 127.1>nul
-
- netsh interface set interface "%NetConnectionID%" disabled
-
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo.
- 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%
- echo 100%%
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo -------------------------------------
- @echo 网卡重启成功!
- @echo -------------------------------------
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @echo.
- @ pause
- goto loop
-
-
-
- :end
-
- Endlocal
-
- ping -n 3 127.1>nul
-
- exit
复制代码
作者: wujunkai 时间: 2020-4-6 09:09
本帖最后由 wujunkai 于 2020-4-6 18:27 编辑
回复 1# wwdzcdb
还可以继续化简,等我有空。。。。- @echo off & setlocal enabledelayedexpansion
- title I P修改小工具 Ver 1.0 【 污、克里里 】
- mode con: cols=64 lines=45 & color 0b
-
- 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
-
- :loop
- cls
- echo=
- echo ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
- echo ※ ※
- echo ※ I P 修 改 小 工 具 v 1.0 ※
- echo ※ ※
- echo ※ ※
- echo ※ 「A」- 自 动 获 取 IP ※
- echo ※ ※
- echo ※ 「0」 —→ 192 . 168 . 0 . 1 ※
- echo ※ ※
- echo ※ 「1」 —→ 192 . 168 . 1 . 1 ※
- echo ※ ※
- echo ※ 「2」 —→ 192 . 168 . 2 . 1 ※
- echo ※ ※
- echo ※ 「3」 —→ 192 . 168 . 3 . 1 ※
- echo ※ ※
- echo ※ 「4」 —→ 192 . 168 . 5 . 1 ※
- echo ※ ※
- echo ※ 「5」 —→ 192 . 168 . 6 . 1 ※
- echo ※ ※
- echo ※ 「6」 —→ 192 . 168 . 9 . 1 ※
- echo ※ ※
- echo ※ 「7」 —→ 192 . 168 . 10 . 1 ※
- echo ※ ※
- echo ※ 「8」 —→ 192 . 168 . 99 . 1 ※
- echo ※ ※
- echo ※ 「9」 —→ 192 . 168 . 100 . 1 ※
- echo ※ ※
- echo ※ 「S」- 手 动 输 入 ※
- echo ※ ※
- echo ※ 「D」- D N S 修 改 ※
- echo ※ ※
- echo ※ 「I」- I P 修 改 ※
- echo ※ ※
- echo ※ 「W」- 网 关 修 改 ※
- echo ※ ※
- echo ※ 「R」- 重 启 网 卡 ※
- echo ※ ※
- echo ※ 「Z」- 退 出 程 序 ※
- echo ※ ※
- echo ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
- echo=
- echo=
-
- set /P ST="请输入序号:"
- if /I "%ST%"=="A" call:setupA
- if /I "%ST%"=="0" call:setup 0
- if /I "%ST%"=="1" call:setup 1
- if /I "%ST%"=="2" call:setup 2
- if /I "%ST%"=="3" call:setup 3
- if /I "%ST%"=="4" call:setup 4
- if /I "%ST%"=="5" call:setup 5
- if /I "%ST%"=="6" call:setup 6
- if /I "%ST%"=="7" call:setup 7
- if /I "%ST%"=="8" call:setup 8
- if /I "%ST%"=="9" call:setup 9
- if /I "%ST%"=="S" call:setupS
- if /I "%ST%"=="D" call:setupD
- if /I "%ST%"=="I" call:setupI
- if /I "%ST%"=="W" call:setupW
- if /i "%ST%"=="R" goto:rebootnet
- if /i "%ST%"=="Z" goto:END
- goto:loop
-
- REM 新IP地址/前缀=Newip
- REM 设置子网掩码=Netmask
- REM 设置网关=Gateway
- REM 设置DNS Sever1=Dns1
- REM 设置DNS Sever2=Dns2
-
- :show
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo=
- 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%
- echo 100%%
- call:endl 5
- echo -------------------------------------
- echo 成功设置本地连接IP地址和DNS
- echo=
- echo 当前 IP 地址:%Newip%
- echo 当前子网掩码:%Netmask%
- echo 当前默认网关:%Gateway%
- echo 当前首选 DNS:%Dns1%
- echo 当前备用 DNS:%Dns2%
- echo -------------------------------------
- call:endl 8
- goto:eof
-
- :setupA
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enabledhcp
- wmic nicconfig where index="%index%" call setDNSServerSearchOrder()
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo=
- 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%
- echo 100%%
- call:endl 5
- echo -------------------------------------
- echo 自动获取IP地址成功!
- echo -------------------------------------
- call:endl 8
- pause
- goto:loop
-
-
- :setup
- set "Newip=192.168.!IP[%~1]!.2"
- set "Gateway=192.168.!IP[%~1]!.1"
- set "Netmask=255.255.255.0"
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call setDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call setTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- call:show
- pause
- goto:loop
-
-
- :setupS
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- echo=
- echo ******手动设置本地连接IP地址,输入完成请回车确定******
- echo=
- echo=
- set /p Newip="请输入 IP 地址:"
- echo=
- set "Netmask=255.255.255.0"
- echo=
- set /p Gateway="请输入默认网关:"
- echo=
- set "Dns1=223.5.5.5"
- set "Dns2=223.6.6.6"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
- wmic nicconfig where index="%index%" call setDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call setTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- call:show
- pause
- goto:loop
-
-
- :setupD
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- echo=
- echo ******手动设置DNS地址,输入完成请回车确定******
- echo=
- echo=
- set /p Dns1="请输入 首选DNS 地址:"
- echo=
- set /p Dns2="请输入 备用DNS 地址:"
-
- wmic nicconfig where index="%index%" call setDNSServerSearchOrder("%Dns1%","%Dns2%")
- wmic nicconfig where index="%index%" call setTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo=
- 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%
- echo 100%%
- call:endl 5
- echo -------------------------------------
- echo D N S 修 改 完 成 !
- echo=
- echo 当前首选 DNS:%Dns1%
- echo 当前备用 DNS:%Dns2%
- echo -------------------------------------
- call:endl 8
- pause
- goto:loop
-
-
- :setupI
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- echo=
- echo ******手动设置IP地址,输入完成请回车确定******
- echo=
- echo=
- set /p Newip="请输入 IP 地址:"
- echo=
- set "Netmask=255.255.255.0"
-
- wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
- wmic nicconfig where index="%index%" call setTcpipNetbios 2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo=
- 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%
- echo 100%%
- call:endl 5
- echo -------------------------------------
- echo I P 修 改 完 成 !
- echo=
- echo 当前 IP 地址:%Newip%
- echo 当前子网掩码:%Netmask%
- echo -------------------------------------
- call:endl 8
- pause
- goto:loop
-
-
- :setupW
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- cls
- echo=
- echo ******手动设置网关地址,输入完成请回车确定******
- echo=
- echo=
- set /p Gateway="请输入默认网关:"
-
- wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo=
- 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%
- echo 100%%
- call:endl 5
- echo -------------------------------------
- echo 网 关 修 改 完 成 !
- echo=
- echo 当前网关地址:%Gateway%
- echo -------------------------------------
- call:endl 8
- pause
- goto:loop
-
-
- :rebootnet
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in (' wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- ping -n 3 127.1>nul
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- cls
- set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
- echo=
- 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%
- echo 100%%
- call:endl 5
- echo -------------------------------------
- echo 网卡重启成功!
- echo -------------------------------------
- call:endl 8
- pause
- goto:loop
-
-
- :endl
- for /L %%a in (1,1,%~1) do echo=
- goto:eof
-
-
- :end
- endlocal
- ping -n 3 127.1>nul
- exit
- goto:eof
复制代码
作者: wwdzcdb 时间: 2020-4-6 17:52
回复 2# wujunkai
大佬辛苦了 期待后续继续精简优化 还望大佬能解说一下思路和用法
作者: wujunkai 时间: 2020-4-6 18:26
回复 3# wwdzcdb
已优化在二楼
强烈建议使用call来代替goto。。。鬼知道我检查变量为什么传不过去用了多久
作者: wwdzcdb 时间: 2020-4-8 17:15
回复 4# wujunkai
谢谢大佬 辛苦了
作者: edison_zhu 时间: 2020-4-9 09:31
首先把无用的空行删除……。
@echo off
echo %date% %time%
echo %date% %time% >>IpCheckerDetailLog.txt
set /a avaNum=0
set /a unReaccNum=0
for /f "delims=" %%i in (ip.txt) do (
Ping.exe -n 1 -w 1 %%i >> IpCheckerDetailLog.txt
if not errorlevel 1 ( echo %%i 在线
echo %%i is avaliable >> IpCheckerResLog.txt
set /a avaNum+=1 ) else ( echo %%i 宕机[Warning]
set /a unReaccNum+=1 )
)
del %cd%\IpCheckerDetailLog.txt
del %cd%\IpCheckerResLog.txt
pause
IP地址放在IP.TXT里即可
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |