我有一个Windows 10个人电脑,有两个网络接口。其中一个接口进入主局域网,其中文件服务器、dns和因特网路由器位于其中。第二个接口是一个小局域网,它有一个PLC和一个人机界面。他们都在同一个局域网内,但在不同的子网上(对不起,我无法改变这一点)。
因此,我有两个物理接口和一个逻辑接口: eth0: DHCP,172.16.x.y,掩码255.255.255.0,默认gw 172.16.x.z eth1:静态192.168.1.158,掩码255.255.255.0静态192.168.19.158,掩码255.255.255.0。
HMI可在192.168.19.135下到达
现在,当我重新启动人机界面时,我启动了ping,以查看何时可以再次访问。这应该是在30多岁以后发生的。但我在80至90年代之后才得到肯定的回答。
Ping wird ausgeführt für 192.168.19.135 mit 32 Bytes Daten:
Antwort von 192.168.19.158: Zielhost nicht erreichbar.
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.(对于德文,我很抱歉,但我认为我们在这里看到的仍然应该是清楚的)我得到了第一个平的另一个答复,而不是第二个。
看来,XP之后的Windows开始做一些“路由魔术”,如果无法在更具体的路由上到达目标,只需将数据发送到默认路由。似乎其他人也有过这个问题
我找到了一些对我来说不是真正的解决方案的“解决方案”(下面将详细介绍)。
我尝试过添加具有不同参数和度量的静态路径。没有变化!静态地添加HMI的MAC没有帮助,因为这个MAC可能会改变。
所以我的问题是:
发布于 2022-02-03 07:20:14
因此,在找不到一个简单的解决方案之后,我决定用我的方式来解决微软通过在窗口上严重破坏路由而造成的问题。
我使用的是参数-S的经典ping,而不是powershell中的cmdlet测试连接。
我代码的ping部分现在看起来如下所示:
$localIPs = (Get-NetIPConfiguration -InterfaceAlias "PLC").IPv4Address.IPAddress
# because this command returns a string, when the interface has a single IP-address but an array of strings if the interface has more than one address, we need to check for this
if ($localIPs.GetType().Name -eq "string") { # only a single IP
$localIP = $localIPs
}
else { # more than one IP
$localIP = $localIPs[0] # since it seems that windows does use the ip address as a synonym for the interface, it's not important which of the addresses of that interface we use. So we're just picking the first one
}
$pingcount = 180
do {
ping $HMI4IP -n 1 -w 1000 -S $localIP | Out-Null # redirect the output of ping to /dev/null
$pingreply = $?
$pingcount = $pingcount - 1
}
until ($pingcount -eq '0' -or $pingreply)
if ($pingreply) {
# code here
}
else {
exit 1337 # return with an error code, we've not reached our target
}为此,我只需要确保连接PLC和人机界面的接口名为"PLC“。而不是将地址作为字符串或地址数组(取决于接口是否有一个或多个地址),而是我必须处理的地址(欢迎使用动态键入.)。这比将这些数据提供给ping更容易(因为测试连接试图变得太聪明而不利于自己的利益)。在$?我相信最后一个命令返回了一个成功,如果它是一个失败,则为假。所以从那以后很容易处理。
据我所知,微软没有关于这种行为的文档,也没有关于如何处理这种行为的文档,我认为这是相当可悲的。
https://serverfault.com/questions/1091710
复制相似问题