2017-03-27 316 views
2

指定IP地址我有一个批处理文件,用于通过单击批处理文件来分配静态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 
+0

'netsh接口IP添加/'不显示'加dns'但'加dnsservers' – JosefZ

+0

我得到什么?与没有wlan适配器的系统上的第一个命令非常相同的错误信息。 – LotPings

回答

0

这个问题似乎是与连接名称。 如果运行

netsh interface ip set address "Wireless Network Connection" static 192.168.1.26 255.255.255.0 192.168.1.1 

"Wireless Network Connection"应该存在完全一样的给定名称为一个接口。它就像您正在引用的别名。

如果你看看你的接口netsh interface ip show config确实存在"Wireless Network Connection"吗?可能是"Wireless Network Connection 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服务器进行设置。

+0

任何人都可以发送批处理文件来连接我的自动网络接口,并通过点击该文件自动分配静态IP地址 – sahil

+0

@sahil,请发布有详细要求的新问题,我会回答。 –

+0

我需要完整的批处理文件,它会自动设置我的无线网络接口(这意味着连接的名称),并通过点击该批处理文件自动设置完整的静态IP配置,请发送批处理文件,因为我已发送给您在我之前的问题中,但它适用于onw行,但对于dns其显示不正确,在某些系统上它工作正常,所以请发送给我正确的文件代码。 – sahil

0

看起来像你试图改变一个不存在的连接。
我第一枚举当前连接:

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