Ping if unsuccessful disable and enable NIC

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bookmaster
Posts: 3
Joined: 11 Feb 2023 03:13

Ping if unsuccessful disable and enable NIC

#1 Post by Bookmaster » 13 May 2023 01:50

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

bxx
Posts: 5
Joined: 09 Mar 2023 03:49

Re: Ping if unsuccessful disable and enable NIC

#2 Post by bxx » 13 May 2023 07:14

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.

Post Reply