[英]how to get ipv4 address of particular adapter via batch script in windows 10
[英]Batch file to update wireless adapter IPv4 properties
我的家庭網絡要求我手動設置IP地址,子網掩碼,路由器IP和兩個DNS服務器。 我想寫一個批處理腳本來為我做。 我在網上找到了一些批處理文件,這些文件可讓您手動輸入靜態IP,但它們並不總是具有其他信息的字段,因此我不想每次都輸入IP地址(這些示例程序會用戶輸入),我只想雙擊文件,然后將其更改為“主頁”模式即可。
那么,用於手動將IP地址,子網掩碼,路由器IP和兩個單獨的DNS服務器設置為恆定值的批處理命令是什么?
這未經測試,應該可以幫助您解決問題,並且可以搜索缺少的DNS命令。
在測試時刪除三個>nul
語句,這樣您就可以看到任何錯誤響應。
三個地方的%%WG111%%
應該是您的NIC的文本描述。
來自:ten.nigriv
主題:回復:netsh
新聞組:alt.msdos.batch.nt
日期:2009年1月17日星期六19:54:51 +0000
在您開始之前,我將快速解釋三個變量,您可能需要更改它們:
1. %G_% is the chosen Default Gateway
On home wireless adapters this is usually the address of the router.
The figure I've used is the default for most Netgear routers.
2. %A_% is your chosen IPAddress
On home systems this is usually set in the range 2-12 of the Gateway Address
3. %S_% is the chosen Subnet Mask
On general home systems this is invariably that which is shown
這是腳本:
::----- START -----
@Echo off & Setlocal enableextensions
Set "G_=192.168.0.1" & Set "A_=192.168.0.7" & Set "S_=255.255.255.0"
>Nul Wmic NICCONFIG WHERE "Description LIKE '%%WG111%%'" CALL EnableStatic "%A_%", "%S_%"
>Nul Wmic NICCONFIG WHERE "Description LIKE '%%WG111%%'" CALL SetGateways "%G_%",1
>Nul Wmic NICCONFIG WHERE "Description LIKE '%%WG111%%'" CALL SetDNSServerSearchOrder "%G_%"
::------ END ------
我用下面的命令編寫了一個批處理文件,以設置我的IP地址,子網掩碼,網關地址和兩個DNS服務器。 確保以管理員身份運行批處理文件。
//this set static IP, mask, and gateway address
netsh int ipv4 set address name="Local Area Connection" source=static address=10.127.86.25 mask=255.255.255.240 gateway=10.127.86.30
//this set static DNS for both preffereed and alternate
netsh interface ipv4 add dns "Local Area Connection" address=10.127.70.1 index=1
netsh interface ipv4 add dns "Local Area Connection" address=10.127.70.2 index=2
如果只需要一台dns服務器,也可以使用以下命令:
netsh int ipv4 set dns name="Local Area Connection" source=static address=10.127.70.1 register=primary validate=no
要將地址和DNS都設置為DHCP,以便它自動提供IP主機,可以使用以下批處理命令:
netsh interface ipv4 set address name="Local Area Connection" source=dhcp
netsh interface ipv4 set dnsservers name="Local Area Connection" source=dhcp
您可能需要檢查所有可用的網絡連接,為此運行以下命令:
netsh interface show interface
要詳細了解,請參考this 。 希望對您有幫助。 讓我知道您是否有任何疑問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.