我的家庭网络要求我手动设置我的IP地址,子网掩码,路由器IP和两个DNS服务器。我想编写一个批处理脚本来为我做这件事。我在网上发现了一些允许你手动输入静态IP的批处理文件,但它们并不总是有其他信息的字段,我不想每次都输入IP地址(这些示例程序需要一个用户输入),我宁愿只是双击文件和繁荣我改为“家”模式。
那么用于手动将IP地址,子网掩码,路由器IP和两个单独的DNS服务器设置为常量值的批处理命令是什么?
答案 0 :(得分:0)
这是未经测试的,应该可以帮助您完成部分工作,并且可以搜索丢失的DNS命令。
在测试时删除三个>nul
语句,以便您可以看到任何错误响应。
三个地方的%%WG111%%
应该是您网卡的文字说明。
来自:ten.nigriv
主题:Re: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 ------
答案 1 :(得分:0)
我编写了一个带有以下命令的批处理文件来设置我的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。 希望对你有所帮助。如果您有任何疑问,请与我们联系。