Batch file 通过使用批处理文件分配ip地址

Batch file 通过使用批处理文件分配ip地址,batch-file,Batch File,我有一个用于分配静态ip的批处理文件,只需单击该批处理文件。但它在某些系统上显示错误(文件名、目录名或卷标语法不正确)。解决办法是什么 我的批处理文件是 netsh interface ip set address "Wireless Network Connection" static 192.168.1.26 255.255.255.0 192.168.1.1 netsh interface ip set dns "Wireless Network Connection" static

我有一个用于分配静态ip的批处理文件,只需单击该批处理文件。但它在某些系统上显示错误(文件名、目录名或卷标语法不正确)。解决办法是什么

我的批处理文件是

 netsh interface ip set address "Wireless Network Connection" static 192.168.1.26 255.255.255.0 192.168.1.1 
netsh interface ip set dns "Wireless Network Connection" static 8.8.8.8
netsh interface ip add dns "Wireless Network Connection" 4.2.2.2

问题似乎出在连接名上。 如果你跑

netsh interface ip set address "Wireless Network Connection" static 192.168.1.26 255.255.255.0 192.168.1.1
“无线网络连接”
应该与该给定名称一样作为接口存在。它就像您正在引用的别名

如果您通过
netsh interface ip show config
查看您的接口,
是否确实存在“无线网络连接”
?可能是类似于
“无线网络连接2”
的其他内容,然后您将得到您发布的确切错误

编辑

根据你的评论

请记住为每一行添加正确的接口名称,但您最近的问题实际上是在最后一行添加DNS服务器

netsh interface ip set address "Connection name goes here" static 192.168.1.26 255.255.255.0 192.168.1.1 
netsh interface ip set dns "Connection name goes here" static 8.8.8.8
netsh interface ip add dnsserver "Connection name goes here" address=4.2.2.2 index=1
注意:您也可以使用

 netsh interface ipv4 add dnsserver "Connection name goes here" address=4.2.2.2 index=1

关于
index=1
,请记住根据您要首先索引的DNS服务器设置它。

看起来您试图更改不存在的连接。
我首先列举了当前的连接:

for /f tokens^=2delims^=^" %%A in (
  'netsh interface ip show config'
) Do Echo %%A
样本输出:

> List-Conn.cmd
LAN-Verbindung
Ethernet 2
Loopback Pseudo-Interface 1

netsh interface ip add/?
不显示
add dns
,但
add dns服务器
在没有wlan适配器的系统上,我收到与第一个命令相同的错误消息。是否有人可以发送批处理文件来连接我的自动网络接口并通过单击该命令自动分配静态ip地址file@sahil,请发布一个新的问题,详细要求,我会回答。我需要一个完整的批处理文件,它可以自动设置我的无线网络接口(它是指连接的名称),并通过单击该批处理文件自动设置完整的静态ip配置,请将批处理文件发送给我,正如我在上一个问题中向您发送的,但对于onw-line来说没有问题,但是对于dns来说它显示不正确,在某些系统上它工作正常,所以请向我发送正确的文件代码。