-1

I have a device which is running on a Windows 10 Enterprise , currently i'm looking for a script which can act as a Connection Manager which is like below.

Attached codes below where I tried using metric value but it doesn't work properly.

$formatstring = "{0} : {1}`n{2}`n" +
                "    + CategoryInfo          : {3}`n" +
                "    + FullyQualifiedErrorId : {4}`n"
$fields = $_.Exception.Message


$gw = "172.21.150.21"

if (Test-Connection -ComputerName $gw -BufferSize 16 -Count 1 -ErrorAction 0 -Quiet)
{
    try
    {
        route change -p 0.0.0.0 MASK 0.0.0.0 192.168.230.21 METRIC 300 IF 13/P
    }
    catch
    {
        Write-Host -Foreground Red -Background Black ($formatstring -f $fields)
    }
}
else
{
    try
    {
        route change -p 0.0.0.0 MASK 0.0.0.0 192.168.230.21 METRIC 1 IF 13/P
    }
    catch
    {
        Write-Host -Foreground Red -Background Black ($formatstring -f $fields)
    }
}

Always connected to Cellular Data ( 3G/4G ) and ping check to the primary IP for every 30 seconds and if the ping fails continuously for 1 mins it should go to secondary which is WiFi and keep the connection till the cellular Data connection is back which means if the 30 second ping success in couple of minutes or hours.

WIFI is using SSID and Cellular Data is using APN, I need some example codes for python or else using powershell.

AppyGG
  • 381
  • 1
  • 6
  • 12

1 Answers1

0

I was creating almost the same script, but I was using WebSockets. I think its better for you to ask one by one question as you move forward your end result.

For example: How can I connect to wifi using CMD or PowerShell? Answer

How can I connect to Mobile Broadband using CMD or PowerShell? Answer

How can I disable a specified network adapter? Answer

How can I ping an IP address from cmd Answer

How to execute a command prompt command from python Answer

Hope these links help you!

Nemanja
  • 174
  • 17
  • The functions your python script should do is: Checking if the internet is available. Sleeping for x amount of time. Switching between WIFI and 4G. Run on Windows startup. – Nemanja Oct 11 '19 at 05:02
  • can you provide me the method sample scripts – Sharron Saint Oct 12 '19 at 08:38
  • You are better of opening a notepad and start coding, you will not find your solution here. – Nemanja Oct 12 '19 at 16:48
  • You can check out the solution I created using Node-Red as a back-end: [websocket-ping-py](https://github.com/lizzardguki/websocket-ping-py) – Nemanja Oct 12 '19 at 17:28