批處理新手入門導讀[視頻教程]批處理基礎視頻教程[視頻教程]VBS基礎視頻教程
[批處理文件精品]批處理版照片整理器[批處理文件精品]純批處理備份&還原驅動在線第三方下載
返回列表 發帖

[文本處理] 根據自動獲取的IP、DNS設置成固定,并自動識別網卡名稱

前半部分已經解決,網卡名稱這部分是在頭痛,以下是前半部分:
  1. @echo off
  2. ipconfig>ipc.txt
  3. netsh interface ip show address>gwc.txt
  4. for /f "delims=: tokens=2" %%a in ('find "IPv4 地址" ipc.txt') do set IP=%%a
  5. for /f "delims=: tokens=2" %%b in ('find "子網掩碼" ipc.txt') do set mask=%%b
  6. for /f "delims=: tokens=2" %%i in ('find "默認網關" gwc.txt') do set gw=%%i
  7. netsh interface ip set address "本地連接" static %IP% %mask% %gw% 0
  8. netsh interface ip set dns name="本地連接" source=static addr=10.46.20.96
  9. netsh interface ip add dns name="本地連接" addr=10.46.20.97 index=2
  10. del ipc.txt
  11. del gwc.txt
復制代碼
各位大神有沒有辦法,本地連接能夠自動識別,好多電腦名稱都不一樣,有本地連接1~5都碰到過

情況比較復雜,遇到過電腦有4塊板載網卡和1塊外置USB無線網卡
【批處理在線視頻分享】http://bbs.bathome.net/thread-31727-1-1.html
【微信公眾號、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html

我幫忙寫的代碼不需要付錢,不用找我要支付寶或微信賬號。如果一定要給,請到微信群給大家發紅吧。

TOP

本地連接一般只有一個,但是后面的數字就不一定是幾了

TOP

用序列遞增變量,獲取時用 for /l 獲取這些變量
這么好的論壇你上哪找
注:請遵守互聯網信息安全,勿用于非法用途,伸手黨直接去某度

TOP

回復 3# duduchong


    我們這邊的實際情況是有幾塊板載網卡就有幾個本地鏈接x
【批處理在線視頻分享】http://bbs.bathome.net/thread-31727-1-1.html
【微信公眾號、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html

我幫忙寫的代碼不需要付錢,不用找我要支付寶或微信賬號。如果一定要給,請到微信群給大家發紅吧。

TOP

可能是我沒表達清楚,我需要使用的電腦上,只有一個本地連接,但是本地連接后面有數字,有些電腦是2,有些是4,所以不需要區別

TOP

不需要區別,就先把無效的本地連接全部刪除,然后你隨便搞了。

TOP

哪位大哥幫我改改,獲取名稱啊:dizzy:

TOP

用了個很SB的辦法解決了
@echo off

ipconfig>ipc.txt

netsh interface ip show address>gwc.txt

for /f "delims=: tokens=2" %%a in ('find "IPv4 地址" ipc.txt') do set IP=%%a

for /f "delims=: tokens=2" %%b in ('find "子網掩碼" ipc.txt') do set mask=%%b

for /f "delims=: tokens=2" %%i in ('find "默認網關" gwc.txt') do set gw=%%i

netsh interface ip set address "本地連接" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地連接" source=static addr=10.46.20.96

netsh interface ip add dns name="本地連接" addr=10.46.20.97 index=2

netsh interface ip set address "本地連接 2" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地連接 2" source=static addr=10.46.20.96

netsh interface ip add dns name="本地連接 2" addr=10.46.20.97 index=2

netsh interface ip set address "本地連接 3" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地連接 3" source=static addr=10.46.20.96

netsh interface ip add dns name="本地連接 3" addr=10.46.20.97 index=2

netsh interface ip set address "本地連接 4" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地連接 4" source=static addr=10.46.20.96

netsh interface ip add dns name="本地連接 4" addr=10.46.20.97 index=2

netsh interface ip set address "以太網" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太網" source=static addr=10.46.20.96

netsh interface ip add dns name="以太網" addr=10.46.20.97 index=2

netsh interface ip set address "以太網 2" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太網 2" source=static addr=10.46.20.96

netsh interface ip add dns name="以太網 2" addr=10.46.20.97 index=2

netsh interface ip set address "以太網 3" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太網 3" source=static addr=10.46.20.96

netsh interface ip add dns name="以太網 3" addr=10.46.20.97 index=2

netsh interface ip set address "以太網 4" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太網 4" source=static addr=10.46.20.96

netsh interface ip add dns name="以太網 4" addr=10.46.20.97 index=2

del ipc.txt

del gwc.txt

TOP

  1. @echo off
  2. ipconfig>ipc.txt
  3. netsh interface ip show address>gwc.txt
  4. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  5. echo NetConnectionID="%NetConnectionID%"
  6. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  7. echo index="%index%"
  8. for /f "delims=: tokens=2" %%a in ('find "IPv4 地址" ipc.txt') do set IP=%%a
  9. for /f "delims=: tokens=2" %%b in ('find "子網掩碼" ipc.txt') do set mask=%%b
  10. for /f "delims=: tokens=2" %%i in ('find "默認網關" gwc.txt') do set gw=%%i
  11. netsh interface ip set address "%NetConnectionID%" static %IP% %mask% %gw% 0
  12. netsh interface ip set dns name="%NetConnectionID%" source=static addr=10.46.20.96
  13. netsh interface ip add dns name="%NetConnectionID%" addr=10.46.20.97 index=2
  14. netsh interface set interface "%NetConnectionID%" disabled
  15. netsh interface set interface "%NetConnectionID%" enable
  16. del ipc.txt
  17. del gwc.txt
復制代碼

TOP

返回列表
36选7开奖结果今天福建