Jump to content

Script to ping and reset connection

DumbTrollface
Go to solution Solved by DumbTrollface,

Found out that ping does indeed return an exit code and that you can check the exit code of the previous programm by using %errorlevel%.

 

@echo off
ping router
if %errorlevel% NEQ 0 (disable_device
	timeout /nobreak /t 10 //Wait 10 seconds
	enable_device
)

And after some testing it seems to work.

 

EDIT: If someone is curious: I use devcon for disabling and enabling the device

Hey folks,

 

I have the problem that I'm using powerline for a wired connection since my wifi is quite slow. But since my home is pretty old the powerline adapter keeps losing connection roughly every hour.

I do have wifi connected but windows still tries to use the wired connection for a few minutes even though it says that it has no connection over ethernet but that wifi works fine.

So my question is: Is there a way to force windows to use both simultaneously or switch immediately?

 

And if not: I already have a script written that resets my ethernet port (which fixes the problem). Can I continously ping my router and if it loses connection do the reset?

 

So something like
 

while (true) { // infinite loop
	int ping = ping.exe //use ping.exe to check connection
	if (ping == ping_failed) {
		reset_ethernet();
	}
	wait(1000);
}

using cmd

Edited by DumbTrollface
fixed typo
Link to comment
Share on other sites

Link to post
Share on other sites

26 minutes ago, DumbTrollface said:

Hey folks,

 

I have the problem that I'm using powerline for a wired connection since my wifi is quite slow. But since my home is pretty old the powerline adapter keeps losing connection roughly every hour.

I do have wifi connected but windows still tries to use the wired connection for a few minutes even though it says that it has no connection over ethernet but that wifi works fine.

So my question is: Is there a way to force windows to use both simultaneously or switch immediately?

 

And if not: I already have a script written that resets my ethernet port (which fixes the problem). Can I continously ping my router and if it loses connection do the reset?

 

So something like
 


while (true) { // infinite loop
	int ping = ping.exe //use ping.exe to check connection
	if (ping == ping_failed) {
		reset_ethernet();
	}
	wait(1000);
}

using cmd

You could use Task Scheduler to run that script as often as you want (every 1 second, 5 seconds, 30 seconds, 5 minutes - whatever).

For Sale: Meraki Bundle

 

iPhone Xr 128 GB Product Red - HP Spectre x360 13" (i5 - 8 GB RAM - 256 GB SSD) - HP ZBook 15v G5 15" (i7-8850H - 16 GB RAM - 512 GB SSD - NVIDIA Quadro P600)

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, wonderforest said:

Just unplug the ethernet wire ?

First of all it's pretty hard to access and secondly I don't really have the time for that. I need my internet for work and can't have any downtime.

 

And if you mean to just continue using wifi: I would go from ~25k down to ~2k down. So that's not really an option

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, dalekphalm said:

You could use Task Scheduler to run that script as often as you want (every 1 second, 5 seconds, 30 seconds, 5 minutes - whatever).

But I only want to do that if the connection is actually down

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, DumbTrollface said:

But I only want to do that if the connection is actually down

Do what? Run the script?

 

You write the script to check the connection (eg: ping), and if the ping fails, the script executes an action (eg: reset ethernet adapter).

 

The Task Scheduler continually runs the script, to check the connection.

 

It would only reset the connection IF a ping test failed.

 

With that in mind, you might need to modify the script to make this work.

 

I guess, if your existing script works as-is, you could just put a shortcut to the script into your startup folder, and start it when you turn your computer on.

For Sale: Meraki Bundle

 

iPhone Xr 128 GB Product Red - HP Spectre x360 13" (i5 - 8 GB RAM - 256 GB SSD) - HP ZBook 15v G5 15" (i7-8850H - 16 GB RAM - 512 GB SSD - NVIDIA Quadro P600)

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, dalekphalm said:

Do what? Run the script?

 

You write the script to check the connection (eg: ping), and if the ping fails, the script executes an action (eg: reset ethernet adapter).

 

The Task Scheduler continually runs the script, to check the connection.

 

It would only reset the connection IF a ping test failed.

 

With that in mind, you might need to modify the script to make this work.

 

I guess, if your existing script works as-is, you could just put a shortcut to the script into your startup folder, and start it when you turn your computer on.

That's what I want. My question is how I check the connection using ping. Does it return a value?

Link to comment
Share on other sites

Link to post
Share on other sites

Found out that ping does indeed return an exit code and that you can check the exit code of the previous programm by using %errorlevel%.

 

@echo off
ping router
if %errorlevel% NEQ 0 (disable_device
	timeout /nobreak /t 10 //Wait 10 seconds
	enable_device
)

And after some testing it seems to work.

 

EDIT: If someone is curious: I use devcon for disabling and enabling the device

Edited by DumbTrollface
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×