简体   繁体   English

将 WiFi 切换 Linux shell 脚本翻译到 Windows10 CMD 或 Z3D265B4E13EEB10DDF17881FA0

[英]Translating WiFi switching Linux shell script to Windows10 CMD or PowerShell

I managed to create a Linux shell script that is able to switch between two different wifi services that very often hang but which can be manually reconnected with success.我设法创建了一个 Linux shell 脚本,该脚本能够在两个经常挂起但可以手动重新连接成功的不同 wifi 服务之间切换。

while (true) do 
    if ! [ "`ping -c 1 -W 1 www.google.it`" ]; then
        if (nmcli connection show --active | grep -c "FirstWiFi"); then
            nmcli connection up id "SecondWiFi"
            echo "switched to SecondWiFi"
        else
            nmcli connection up id "FirstWiFi"
            echo "switched to FirstWiFi"
        fi
    fi
done

I am not suggesting to use this script because I do not know if it is safe.我不建议使用这个脚本,因为我不知道它是否安全。

Now I need the same functionality on a Windows 10 system.现在我需要在 Windows 10 系统上使用相同的功能。

I know that CMD is more limited than the bash shell or the like.我知道 CMD 比 bash shell 等更受限制。 But Windows 10 has also PowerShell.但 Windows 10 也有 PowerShell。

As you can see the script is very simple so I think it can be translated.如您所见,脚本非常简单,因此我认为可以翻译。 I do not know how to do it.我不知道怎么做。

Maybe some easy suggestions can be found here.也许可以在这里找到一些简单的建议。

I don't have nmcli but it goes something like this:我没有 nmcli,但它是这样的:

while ($true) {
    if (! (test-connection www.google.it -count 1 -ea 0)) {
        if (nmcli connection show --active | select-string FirstWiFi) {
            nmcli connection up id "SecondWiFi"
            echo "switched to SecondWiFi"
        } else {
            nmcli connection up id "FirstWiFi"
            echo "switched to FirstWiFi"
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM