我的家庭网络要求我手动设置IP地址、子网掩码、路由器IP和两个DNS服务器。我想写一个批处理脚本,它将为我做到这一点。我在网上找到了一些批处理文件,允许你手动输入静态IP,但它们并不总是有其他信息的字段,而且我不想每次都输入IP地址(这些示例程序需要用户输入),我宁愿双击文件,然后将我切换到"home“模式。
那么,手动将IP地址、子网掩码、路由器IP和两个单独的DNS服务器设置为常量值的批处理命令是什么?
发布于 2015-07-09 04:00:14
我已经用下面的命令写了一个批处理文件来设置我的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。希望这对你有帮助。如果你有任何疑问,请告诉我。
发布于 2014-03-24 09:34:42
这是未经测试的,应该可以让您完成一部分工作,您可以搜索缺少的DNS命令。
在测试时删除这三条>nul语句,这样您就可以看到任何错误响应。
三个位置的%%WG111%%可能是您的网卡的文本描述。
来自: ten.nigriv
主题: Re: netsh
新闻组: alt.msdos.batch.nt
日期: Sat,Jan 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 ------https://stackoverflow.com/questions/22596563
复制相似问题