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

[网络连接] 大佬帮忙精简优化IP小工具BAT代码

自己写了个IP小工具   代码有些累赘 相同代码太多   请大佬帮忙优化精简
  1. @echo off
  2. title I P修改小工具  Ver 1.0 【 污、克里里 】
  3. mode con: cols=64 lines=45 & color 0b
  4. :loop
  5. CLS
  6. @echo.
  7. @echo     ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
  8. @echo     ※                                                    ※
  9. @echo     ※           I P 修 改 小 工 具 v 1.0                 ※
  10. @echo     ※                                                    ※
  11. @echo     ※                                                    ※
  12. @echo     ※      「A」-   自   动   获   取   IP               ※
  13. @echo     ※                                                    ※
  14. @echo     ※      「0」  —→ 192 . 168 .   0 . 1               ※
  15. @echo     ※                                                    ※
  16. @echo     ※      「1」  —→ 192 . 168 .   1 . 1               ※
  17. @echo     ※                                                    ※
  18. @echo     ※      「2」  —→ 192 . 168 .   2 . 1               ※
  19. @echo     ※                                                    ※
  20. @echo     ※      「3」  —→ 192 . 168 .   3 . 1               ※
  21. @echo     ※                                                    ※
  22. @echo     ※      「4」  —→ 192 . 168 .   5 . 1               ※
  23. @echo     ※                                                    ※
  24. @echo     ※      「5」  —→ 192 . 168 .   6 . 1               ※
  25. @echo     ※                                                    ※
  26. @echo     ※      「6」  —→ 192 . 168 .   9 . 1               ※
  27. @echo     ※                                                    ※
  28. @echo     ※      「7」  —→ 192 . 168 .  10 . 1               ※
  29. @echo     ※                                                    ※
  30. @echo     ※      「8」  —→ 192 . 168 .  99 . 1               ※
  31. @echo     ※                                                    ※
  32. @echo     ※      「9」  —→ 192 . 168 . 100 . 1               ※
  33. @echo     ※                                                    ※
  34. @echo     ※      「S」-   手    动    输    入                 ※
  35. @echo     ※                                                    ※
  36. @echo     ※      「D」-   D   N   S   修    改                 ※
  37. @echo     ※                                                    ※
  38. @echo     ※      「I」-   I     P     修    改                 ※
  39. @echo     ※                                                    ※
  40. @echo     ※      「W」-   网    关    修    改                 ※
  41. @echo     ※                                                    ※
  42. @echo     ※      「R」-   重    启    网    卡                 ※
  43. @echo     ※                                                    ※
  44. @echo     ※      「Z」-   退    出    程    序                 ※
  45. @echo     ※                                                    ※
  46. @echo     ※※※※※※※※※※※※※※※※※※※※※※※※※※※※
  47. @echo.
  48. @echo.
  49. @ SET /P ST="请输入序号:"
  50. echo.
  51. if /I "%ST%"=="A" goto setupA
  52. if /I "%ST%"=="0" goto setup0
  53. if /I "%ST%"=="1" goto setup1
  54. if /I "%ST%"=="2" goto setup2
  55. if /I "%ST%"=="3" goto setup3
  56. if /I "%ST%"=="4" goto setup4
  57. if /I "%ST%"=="5" goto setup5
  58. if /I "%ST%"=="6" goto setup6
  59. if /I "%ST%"=="7" goto setup7
  60. if /I "%ST%"=="8" goto setup8
  61. if /I "%ST%"=="9" goto setup9
  62. if /I "%ST%"=="S" goto setupS
  63. if /I "%ST%"=="D" goto setupD
  64. if /I "%ST%"=="I" goto setupI
  65. if /I "%ST%"=="W" goto 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. :setupA
  75. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  76. echo NetConnectionID="%NetConnectionID%"
  77. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  78. echo index="%index%"
  79. wmic nicconfig where index="%index%" call enabledhcp
  80. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder()
  81. netsh interface set interface "%NetConnectionID%" disabled
  82. netsh interface set interface "%NetConnectionID%" enable
  83. cls
  84. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  85. echo.
  86. 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%
  87. echo    100%%
  88. @echo.
  89. @echo.
  90. @echo.
  91. @echo.
  92. @echo.
  93. @echo              -------------------------------------
  94. @echo                    自动获取IP地址成功!
  95. @echo              -------------------------------------
  96. @echo.
  97. @echo.
  98. @echo.
  99. @echo.
  100. @echo.
  101. @echo.
  102. @echo.
  103. @echo.
  104. @ pause
  105. goto loop
  106. :setup0
  107. set "Newip=192.168.0.2"
  108. set "Netmask=255.255.255.0"
  109. set "Gateway=192.168.0.1"
  110. set "Dns1=223.5.5.5"
  111. set "Dns2=223.6.6.6"
  112. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  113. echo NetConnectionID="%NetConnectionID%"
  114. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  115. echo index="%index%"
  116. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  117. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  118. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  119. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  120. netsh interface set interface "%NetConnectionID%" disabled
  121. netsh interface set interface "%NetConnectionID%" enable
  122. cls
  123. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  124. echo.
  125. 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%
  126. echo    100%%
  127. @echo.
  128. @echo.
  129. @echo.
  130. @echo.
  131. @echo.
  132. @echo              -------------------------------------
  133. @echo                成功设置本地连接IP地址和DNS
  134. @echo.
  135. @echo                当前 IP 地址:%Newip%
  136. @echo                当前子网掩码:%Netmask%  
  137. @echo                当前默认网关:%Gateway%
  138. @echo                当前首选 DNS:%Dns1%
  139. @echo                当前备用 DNS:%Dns2%   
  140. @echo              -------------------------------------
  141. @echo.
  142. @echo.
  143. @echo.
  144. @echo.
  145. @echo.
  146. @echo.
  147. @echo.
  148. @echo.
  149. @ pause
  150. goto loop
  151. :setup1
  152. set "Newip=192.168.1.2"
  153. set "Netmask=255.255.255.0"
  154. set "Gateway=192.168.1.1"
  155. set "Dns1=223.5.5.5"
  156. set "Dns2=223.6.6.6"
  157. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  158. echo NetConnectionID="%NetConnectionID%"
  159. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  160. echo index="%index%"
  161. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  162. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  163. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  164. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  165. netsh interface set interface "%NetConnectionID%" disabled
  166. netsh interface set interface "%NetConnectionID%" enable
  167. cls
  168. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  169. echo.
  170. 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%
  171. echo    100%%
  172. @echo.
  173. @echo.
  174. @echo.
  175. @echo.
  176. @echo.
  177. @echo              -------------------------------------
  178. @echo                成功设置本地连接IP地址和DNS
  179. @echo.
  180. @echo                当前 IP 地址:%Newip%
  181. @echo                当前子网掩码:%Netmask%  
  182. @echo                当前默认网关:%Gateway%
  183. @echo                当前首选 DNS:%Dns1%
  184. @echo                当前备用 DNS:%Dns2%   
  185. @echo              -------------------------------------
  186. @echo.
  187. @echo.
  188. @echo.
  189. @echo.
  190. @echo.
  191. @echo.
  192. @echo.
  193. @echo.
  194. @ pause
  195. goto loop
  196. :setup2
  197. set "Newip=192.168.2.2"
  198. set "Netmask=255.255.255.0"
  199. set "Gateway=192.168.2.1"
  200. set "Dns1=223.5.5.5"
  201. set "Dns2=223.6.6.6"
  202. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  203. echo NetConnectionID="%NetConnectionID%"
  204. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  205. echo index="%index%"
  206. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  207. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  208. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  209. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  210. netsh interface set interface "%NetConnectionID%" disabled
  211. netsh interface set interface "%NetConnectionID%" enable
  212. cls
  213. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  214. echo.
  215. 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%
  216. echo    100%%
  217. @echo.
  218. @echo.
  219. @echo.
  220. @echo.
  221. @echo.
  222. @echo              -------------------------------------
  223. @echo                成功设置本地连接IP地址和DNS
  224. @echo.
  225. @echo                当前 IP 地址:%Newip%
  226. @echo                当前子网掩码:%Netmask%  
  227. @echo                当前默认网关:%Gateway%
  228. @echo                当前首选 DNS:%Dns1%
  229. @echo                当前备用 DNS:%Dns2%   
  230. @echo              -------------------------------------
  231. @echo.
  232. @echo.
  233. @echo.
  234. @echo.
  235. @echo.
  236. @echo.
  237. @echo.
  238. @echo.
  239. @ pause
  240. goto loop
  241. :setup3
  242. set "Newip=192.168.3.2"
  243. set "Netmask=255.255.255.0"
  244. set "Gateway=192.168.3.1"
  245. set "Dns1=223.5.5.5"
  246. set "Dns2=223.6.6.6"
  247. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  248. echo NetConnectionID="%NetConnectionID%"
  249. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  250. echo index="%index%"
  251. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  252. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  253. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  254. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  255. netsh interface set interface "%NetConnectionID%" disabled
  256. netsh interface set interface "%NetConnectionID%" enable
  257. cls
  258. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  259. echo.
  260. 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%
  261. echo    100%%
  262. @echo.
  263. @echo.
  264. @echo.
  265. @echo.
  266. @echo.
  267. @echo              -------------------------------------
  268. @echo                成功设置本地连接IP地址和DNS
  269. @echo.
  270. @echo                当前 IP 地址:%Newip%
  271. @echo                当前子网掩码:%Netmask%  
  272. @echo                当前默认网关:%Gateway%
  273. @echo                当前首选 DNS:%Dns1%
  274. @echo                当前备用 DNS:%Dns2%   
  275. @echo              -------------------------------------
  276. @echo.
  277. @echo.
  278. @echo.
  279. @echo.
  280. @echo.
  281. @echo.
  282. @echo.
  283. @echo.
  284. @ pause
  285. goto loop
  286. :setup4
  287. set "Newip=192.168.5.2"
  288. set "Netmask=255.255.255.0"
  289. set "Gateway=192.168.5.1"
  290. set "Dns1=223.5.5.5"
  291. set "Dns2=223.6.6.6"
  292. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  293. echo NetConnectionID="%NetConnectionID%"
  294. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  295. echo index="%index%"
  296. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  297. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  298. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  299. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  300. netsh interface set interface "%NetConnectionID%" disabled
  301. netsh interface set interface "%NetConnectionID%" enable
  302. cls
  303. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  304. echo.
  305. 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%
  306. echo    100%%
  307. @echo.
  308. @echo.
  309. @echo.
  310. @echo.
  311. @echo.
  312. @echo              -------------------------------------
  313. @echo                成功设置本地连接IP地址和DNS
  314. @echo.
  315. @echo                当前 IP 地址:%Newip%
  316. @echo                当前子网掩码:%Netmask%  
  317. @echo                当前默认网关:%Gateway%
  318. @echo                当前首选 DNS:%Dns1%
  319. @echo                当前备用 DNS:%Dns2%   
  320. @echo              -------------------------------------
  321. @echo.
  322. @echo.
  323. @echo.
  324. @echo.
  325. @echo.
  326. @echo.
  327. @echo.
  328. @echo.
  329. @ pause
  330. goto loop
  331. :setup5
  332. set "Newip=192.168.6.2"
  333. set "Netmask=255.255.255.0"
  334. set "Gateway=192.168.6.1"
  335. set "Dns1=223.5.5.5"
  336. set "Dns2=223.6.6.6"
  337. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  338. echo NetConnectionID="%NetConnectionID%"
  339. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  340. echo index="%index%"
  341. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  342. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  343. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  344. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  345. netsh interface set interface "%NetConnectionID%" disabled
  346. netsh interface set interface "%NetConnectionID%" enable
  347. cls
  348. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  349. echo.
  350. 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%
  351. echo    100%%
  352. @echo.
  353. @echo.
  354. @echo.
  355. @echo.
  356. @echo.
  357. @echo              -------------------------------------
  358. @echo                成功设置本地连接IP地址和DNS
  359. @echo.
  360. @echo                当前 IP 地址:%Newip%
  361. @echo                当前子网掩码:%Netmask%  
  362. @echo                当前默认网关:%Gateway%
  363. @echo                当前首选 DNS:%Dns1%
  364. @echo                当前备用 DNS:%Dns2%   
  365. @echo              -------------------------------------
  366. @echo.
  367. @echo.
  368. @echo.
  369. @echo.
  370. @echo.
  371. @echo.
  372. @echo.
  373. @echo.
  374. @ pause
  375. goto loop
  376. :setup6
  377. set "Newip=192.168.9.2"
  378. set "Netmask=255.255.255.0"
  379. set "Gateway=192.168.9.1"
  380. set "Dns1=223.5.5.5"
  381. set "Dns2=223.6.6.6"
  382. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  383. echo NetConnectionID="%NetConnectionID%"
  384. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  385. echo index="%index%"
  386. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  387. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  388. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  389. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  390. netsh interface set interface "%NetConnectionID%" disabled
  391. netsh interface set interface "%NetConnectionID%" enable
  392. cls
  393. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  394. echo.
  395. 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%
  396. echo    100%%
  397. @echo.
  398. @echo.
  399. @echo.
  400. @echo.
  401. @echo.
  402. @echo              -------------------------------------
  403. @echo                成功设置本地连接IP地址和DNS
  404. @echo.
  405. @echo                当前 IP 地址:%Newip%
  406. @echo                当前子网掩码:%Netmask%  
  407. @echo                当前默认网关:%Gateway%
  408. @echo                当前首选 DNS:%Dns1%
  409. @echo                当前备用 DNS:%Dns2%   
  410. @echo              -------------------------------------
  411. @echo.
  412. @echo.
  413. @echo.
  414. @echo.
  415. @echo.
  416. @echo.
  417. @echo.
  418. @echo.
  419. @ pause
  420. goto loop
  421. :setup7
  422. set "Newip=192.168.10.2"
  423. set "Netmask=255.255.255.0"
  424. set "Gateway=192.168.10.1"
  425. set "Dns1=223.5.5.5"
  426. set "Dns2=223.6.6.6"
  427. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  428. echo NetConnectionID="%NetConnectionID%"
  429. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  430. echo index="%index%"
  431. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  432. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  433. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  434. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  435. netsh interface set interface "%NetConnectionID%" disabled
  436. netsh interface set interface "%NetConnectionID%" enable
  437. cls
  438. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  439. echo.
  440. 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%
  441. echo    100%%
  442. @echo.
  443. @echo.
  444. @echo.
  445. @echo.
  446. @echo.
  447. @echo              -------------------------------------
  448. @echo                成功设置本地连接IP地址和DNS
  449. @echo.
  450. @echo                当前 IP 地址:%Newip%
  451. @echo                当前子网掩码:%Netmask%  
  452. @echo                当前默认网关:%Gateway%
  453. @echo                当前首选 DNS:%Dns1%
  454. @echo                当前备用 DNS:%Dns2%   
  455. @echo              -------------------------------------
  456. @echo.
  457. @echo.
  458. @echo.
  459. @echo.
  460. @echo.
  461. @echo.
  462. @echo.
  463. @echo.
  464. @ pause
  465. goto loop
  466. :setup8
  467. set "Newip=192.168.99.2"
  468. set "Netmask=255.255.255.0"
  469. set "Gateway=192.168.99.1"
  470. set "Dns1=223.5.5.5"
  471. set "Dns2=223.6.6.6"
  472. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  473. echo NetConnectionID="%NetConnectionID%"
  474. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  475. echo index="%index%"
  476. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  477. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  478. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  479. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  480. netsh interface set interface "%NetConnectionID%" disabled
  481. netsh interface set interface "%NetConnectionID%" enable
  482. cls
  483. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  484. echo.
  485. 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%
  486. echo    100%%
  487. @echo.
  488. @echo.
  489. @echo.
  490. @echo.
  491. @echo.
  492. @echo              -------------------------------------
  493. @echo                成功设置本地连接IP地址和DNS
  494. @echo.
  495. @echo                当前 IP 地址:%Newip%
  496. @echo                当前子网掩码:%Netmask%  
  497. @echo                当前默认网关:%Gateway%
  498. @echo                当前首选 DNS:%Dns1%
  499. @echo                当前备用 DNS:%Dns2%   
  500. @echo              -------------------------------------
  501. @echo.
  502. @echo.
  503. @echo.
  504. @echo.
  505. @echo.
  506. @echo.
  507. @echo.
  508. @echo.
  509. @ pause
  510. goto loop
  511. :setup9
  512. set "Newip=192.168.100.2"
  513. set "Netmask=255.255.255.0"
  514. set "Gateway=192.168.100.1"
  515. set "Dns1=223.5.5.5"
  516. set "Dns2=223.6.6.6"
  517. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  518. echo NetConnectionID="%NetConnectionID%"
  519. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  520. echo index="%index%"
  521. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  522. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  523. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  524. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  525. netsh interface set interface "%NetConnectionID%" disabled
  526. netsh interface set interface "%NetConnectionID%" enable
  527. cls
  528. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  529. echo.
  530. 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%
  531. echo    100%%
  532. @echo.
  533. @echo.
  534. @echo.
  535. @echo.
  536. @echo.
  537. @echo              -------------------------------------
  538. @echo                成功设置本地连接IP地址和DNS
  539. @echo.
  540. @echo                当前 IP 地址:%Newip%
  541. @echo                当前子网掩码:%Netmask%  
  542. @echo                当前默认网关:%Gateway%
  543. @echo                当前首选 DNS:%Dns1%
  544. @echo                当前备用 DNS:%Dns2%   
  545. @echo              -------------------------------------
  546. @echo.
  547. @echo.
  548. @echo.
  549. @echo.
  550. @echo.
  551. @echo.
  552. @echo.
  553. @echo.
  554. @ pause
  555. goto loop
  556. :setupS
  557. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  558. echo NetConnectionID="%NetConnectionID%"
  559. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  560. echo index="%index%"
  561. cls
  562. @echo.
  563. @echo       ******手动设置本地连接IP地址,输入完成请回车确定******
  564. @echo.
  565. @echo.
  566. set /p Newip="请输入 IP 地址:"
  567. @echo.
  568. set "Netmask=255.255.255.0"
  569. @echo.
  570. set /p Gateway="请输入默认网关:"
  571. @echo.
  572. set "Dns1=223.5.5.5"
  573. set "Dns2=223.6.6.6"
  574. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  575. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  576. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  577. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  578. netsh interface set interface "%NetConnectionID%" disabled
  579. netsh interface set interface "%NetConnectionID%" enable
  580. cls
  581. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  582. echo.
  583. 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%
  584. echo    100%%
  585. @echo.
  586. @echo.
  587. @echo.
  588. @echo.
  589. @echo.
  590. @echo              -------------------------------------
  591. @echo                成功设置本地连接IP地址和DNS
  592. @echo.
  593. @echo                当前 IP 地址:%Newip%
  594. @echo                当前子网掩码:%Netmask%  
  595. @echo                当前默认网关:%Gateway%
  596. @echo                当前首选 DNS:%Dns1%
  597. @echo                当前备用 DNS:%Dns2%   
  598. @echo              -------------------------------------
  599. @echo.
  600. @echo.
  601. @echo.
  602. @echo.
  603. @echo.
  604. @echo.
  605. @echo.
  606. @echo.
  607. @ pause
  608. goto loop
  609. :setupD
  610. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  611. echo NetConnectionID="%NetConnectionID%"
  612. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  613. echo index="%index%"
  614. cls
  615. @echo.
  616. @echo       ******手动设置DNS地址,输入完成请回车确定******
  617. @echo.
  618. @echo.
  619. set /p Dns1="请输入 首选DNS 地址:"
  620. @echo.
  621. set /p Dns2="请输入 备用DNS 地址:"
  622. wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%Dns1%","%Dns2%")
  623. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  624. netsh interface set interface "%NetConnectionID%" disabled
  625. netsh interface set interface "%NetConnectionID%" enable
  626. cls
  627. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  628. echo.
  629. 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%
  630. echo    100%%
  631. @echo.
  632. @echo.
  633. @echo.
  634. @echo.
  635. @echo.
  636. @echo              -------------------------------------
  637. @echo                   D N S 修 改 完 成 !
  638. @echo.
  639. @echo                当前首选 DNS:%Dns1%
  640. @echo                当前备用 DNS:%Dns2%   
  641. @echo              -------------------------------------
  642. @echo.
  643. @echo.
  644. @echo.
  645. @echo.
  646. @echo.
  647. @echo.
  648. @echo.
  649. @echo.
  650. @ pause
  651. goto loop
  652. :setupI
  653. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  654. echo NetConnectionID="%NetConnectionID%"
  655. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  656. echo index="%index%"
  657. cls
  658. @echo.
  659. @echo       ******手动设置IP地址,输入完成请回车确定******
  660. @echo.
  661. @echo.
  662. set /p Newip="请输入 IP 地址:"
  663. @echo.
  664. set "Netmask=255.255.255.0"
  665. wmic nicconfig where index="%index%" call enablestatic("%Newip%"),("%Netmask%")
  666. wmic nicconfig where index="%index%" call SetTcpipNetbios 2
  667. netsh interface set interface "%NetConnectionID%" disabled
  668. netsh interface set interface "%NetConnectionID%" enable
  669. cls
  670. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  671. echo.
  672. 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%
  673. echo    100%%
  674. @echo.
  675. @echo.
  676. @echo.
  677. @echo.
  678. @echo.
  679. @echo              -------------------------------------
  680. @echo                    I  P  修 改 完 成 !
  681. @echo.
  682. @echo                当前 IP 地址:%Newip%
  683. @echo                当前子网掩码:%Netmask%  
  684. @echo              -------------------------------------
  685. @echo.
  686. @echo.
  687. @echo.
  688. @echo.
  689. @echo.
  690. @echo.
  691. @echo.
  692. @echo.
  693. @ pause
  694. goto loop
  695. :setupW
  696. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  697. echo NetConnectionID="%NetConnectionID%"
  698. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  699. echo index="%index%"
  700. cls
  701. @echo.
  702. @echo       ******手动设置网关地址,输入完成请回车确定******
  703. @echo.
  704. @echo.
  705. set /p Gateway="请输入默认网关:"
  706. wmic nicconfig where index="%index%" call setgateways("%Gateway%"),(1)
  707. netsh interface set interface "%NetConnectionID%" disabled
  708. netsh interface set interface "%NetConnectionID%" enable
  709. cls
  710. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  711. echo.
  712. 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%
  713. echo    100%%
  714. @echo.
  715. @echo.
  716. @echo.
  717. @echo.
  718. @echo.
  719. @echo              -------------------------------------
  720. @echo                   网 关 修 改 完 成 !
  721. @echo.
  722. @echo                当前网关地址:%Gateway%
  723. @echo              -------------------------------------
  724. @echo.
  725. @echo.
  726. @echo.
  727. @echo.
  728. @echo.
  729. @echo.
  730. @echo.
  731. @echo.
  732. @ pause
  733. goto loop
  734. :rebootnet
  735. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  736. echo NetConnectionID="%NetConnectionID%"
  737. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  738. echo index="%index%"
  739. ping -n 3 127.1>nul
  740. netsh interface set interface "%NetConnectionID%" disabled
  741. netsh interface set interface "%NetConnectionID%" enable
  742. cls
  743. set a=^set /p=■%b%^<nul^&ping/n 0 127.1^>nul^&
  744. echo.
  745. 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%
  746. echo    100%%
  747. @echo.
  748. @echo.
  749. @echo.
  750. @echo.
  751. @echo.
  752. @echo              -------------------------------------
  753. @echo                        网卡重启成功!
  754. @echo              -------------------------------------
  755. @echo.
  756. @echo.
  757. @echo.
  758. @echo.
  759. @echo.
  760. @echo.
  761. @echo.
  762. @echo.
  763. @ pause
  764. goto loop
  765. :end
  766. Endlocal
  767. ping -n 3 127.1>nul
  768. exit
复制代码

回复 2# wujunkai


    大佬辛苦了     期待后续继续精简优化        还望大佬能解说一下思路和用法

TOP

回复 4# wujunkai


    谢谢大佬  辛苦了

TOP

返回列表