gpt4 book ai didi

windows - 将正在使用的网卡批量设置为变量

转载 作者:可可西里 更新时间:2023-11-01 10:47:00 25 4
gpt4 key购买 nike

因此,我必须设置静态 ip 的默认网关以及 WINS 和 dns,而对于许多 Windows 系统(包括 Windows 7 和 XP)则不能。我制作了一个批处理脚本来帮助我使用 netsh。问题不是每个网络接口(interface)名称都相同。在大多数情况下,它是“本地连接”,但有些是“以太网”或“无线连接”等等。所以这是我脚本中的一行:

netsh interface ip set address "Local Area Connection"static 192.168.%Range%.%IP_Last% 255.255.255.0 192.168.%Range%.1

像 %Range% 这样的变量是在用户输入时提前设置的。无论如何,我要问的是我怎样才能到达我可以使用的地方:

netsh 接口(interface) ip 设置地址“%NIC_NAME%”静态 192.168.%Range%.%IP_Last% 255.255.255.0 192.168.%Range%.1

这样它就可以在任何系统上运行。我只希望它使用当前事件的网卡名称。非常感谢您的帮助!!

最佳答案

您可以使用 wmi 查找事件适配器,根据需要调整以下代码并选择名称而不是 ip 地址:

strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration" _
& " where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
If Instr(1, IPConfig.IPAddress(i), "169.") = 0 Then


WScript.Echo IPConfig.IPAddress(i)
ELSE
END IF
Next
End If
Next

关于windows - 将正在使用的网卡批量设置为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20183467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com