-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet_fail_script_v2.bat
More file actions
executable file
·51 lines (40 loc) · 1.39 KB
/
Copy pathnet_fail_script_v2.bat
File metadata and controls
executable file
·51 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@echo off
set /A FAILNO=0
REM FAILNO is the number of back to back failiures used to stop the script if the net is down for a long time
set /A CONNFAILNO=0
REM CONNFAILNO refers to the number of times the connection has failed not back to back
set /A PREVSTATE=0
REM a prevstate of 0 means it was up before, 1 means it was down
:start
timeout 10
IF /I %FAILNO% EQU 400 goto :logstop
ping -n 2 8.8.8.8
if %errorlevel% equ 1 (
echo "internet off"
goto :down)
if %errorlevel% equ 0 (
echo "internet on"
goto :up)
:up
echo up
echo "External IP Retrieved at: " %date% %time% > curExtIP.txt & nslookup myip.opendns.com. resolver1.opendns.com | find "Address: " >> curExtIP.txt
set /A PREVSTATE=0
cls
goto start
:down
echo down
IF /I %PREVSTATE% EQU 0 (set /A CONNFAILNO=%CONNFAILNO% + 1)
echo "CONNECTION FAILIURE" >> %CONNFAILNO%_failiurelog.txt
echo %date% %time% >> %CONNFAILNO%_failiurelog.txt
echo "The current internal IP is: " >> %CONNFAILNO%_failiurelog.txt
ipconfig | find "IPv4 Address." >> %CONNFAILNO%_failiurelog.txt
echo "The last known external IP was: " >> %CONNFAILNO%_failiurelog.txt
type curExtIP.txt>>%CONNFAILNO%_failiurelog.txt
echo "----------------------">>%CONNFAILNO%_failiurelog.txt
set /A FAILNO=%FAILNO% + 1
set /A PREVSTATE=1
cls
goto start
:logstop
echo "LOGGING STOPPED HIT THE 20 FAILIURES LIMIT">>failiurelog.txt
cls