Page 1 of 1

Ping if unsuccessful disable and enable NIC

Posted: 13 May 2023 01:50
by Bookmaster
Hello,

I have some issues with a computer which for some for me unknown reason goes out of network. Until I find a problem and solution I would like to have a script that will:

- Ping xxx.xxx.xxx.xxx
- If get response does nothing
- If don't get a response have to check again within 180 sec and if don't get response disable NIC and enable it again

script has to do that process every 15 minutes (if that is not too much of repeating). I know that I can put a script into task scheduler for this.

ipconfig:

https://freeimage.host/i/HUlLeWP


thanks for help in advance

BM

Re: Ping if unsuccessful disable and enable NIC

Posted: 13 May 2023 07:14
by bxx
Here's what I came up with, it's all one line:

Code: Select all

ping 192.0.2.1 && echo all good || (timeout 180 & ping 192.0.2.1 || (netsh interface set interface "Adapter" disable && netsh interface set interface "Adapter" enable))
To get the name of your network adapter, you can run "netsh interface show interface".
This needs to be run as admin obviously.