-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetwork_Resetter.bat
3259 lines (2728 loc) · 103 KB
/
Network_Resetter.bat
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
REM *****************************************************************
REM ************ USE CAUTION WHEN EDITING! *************
REM *****************************************************************
CALL :INITPROG
REM -----Program Info-----
REM Name: Network Resetter
REM Revision:
SET rvsn=r186
REM Branch:
SET Branch=
REM
REM Description: Fixes network connection by trying each of the following:
REM 1) Reset Network Connection (Quick Reset)
REM 2) Reset IP Address
REM 3) Reset Network Connection (Slow Reset)
REM
REM Author: Lectrode
REM Website: http://electrodexs.net
REM Email: [email protected]
REM
REM Notes: This is easiest read in a program such as Notepad++
REM and using the font "Curier New"
REM
REM If it seems stuck on "Resetting IP Address"
REM don't worry about it. It should get past it within a
REM few minutes. If it persists longer than 10 minutes,
REM email me and I'll help you. If this happens often, you
REM can disable it under "Advanced Settings"
REM
REM If after running the program it still won't connect, try
REM increasing the number of MINUTES to wait.
REM
REM If you close the program while it is attempting to fix
REM your network connection, the network connection may still
REM be disabled. To fix this, re-run this program.
REM You can set MINUTES to 0 for a quick run.
REM
REM Possible error messages you may recieve:
REM
REM "This Operating System is not currently supported."
REM -The only thing you can do in this case is email me
REM the name of the Operating System and I'll try to add
REM support for it.
REM You can bypass the OS detection below in "Advanced
REM Settings", but the program may exhibit unusual behavior.
REM
REM "Could not find <network> | This program requires a valid
REM network connection | please open with notepad for more information"
REM -To fix this please correct the NETWORK setting.
REM
REM This program is protected under the GPLv3 License.
REM http://www.gnu.org/licenses/gpl.html
REM ************Alternate Settings****************
REM These settings are overriden by default. To enable these
REM settings, please set USE_ALTERNATE_SETTINGS to 1
REM NOTE: Changing the settings via the GUI will not change
REM the values shown below. These "Alternate" settings
REM are provided for those who do not wish to use the
REM GUI to set them and/or save them to an external
REM file.
SET USE_ALTERNATE_SETTINGS=0
SET MINUTES=10
SET NETWORK=Wireless Network Connection
SET CONTINUOUS=1
SET AUTO_RETRY=1
SET AUTOUPDATE=0
SET CHECK_DELAY=1
SET SHOW_ALL_ALERTS=1
SET SHOW_ADVANCED_TESTING=1
SET SLWMSG=0
SET TIMER_REFRESH_RATE=1
SET START_AT_LOGON=0
SET START_MINIMIZED=0
SET UPDATECHANNEL=2
SET CHECKUPDATEFREQ=5
SET USELOGGING=1
SET OMIT_USER_INPUT=0
SET SKIP_INITIAL_NTWK_TEST=0
SET USE_IP_RESET=1
SET USE_NETWORK_RESET_FAST=1
SET USE_NETWORK_RESET=1
SET USE_RESET_ROUTE_TABLE=0
SET TREAT_TIMEOUTS_AS_DISCONNECT=0
SET ONLY_ONE_NETWORK_NAME_TEST=1
SET OS_DETECT_OVERRIDE=0
:TOP
REM *************Main Code**************
::PROGRAMMER TOOLS
::set NoECHO to :: to show raw commands
SET NoECHO=
SET SIMULATE=0
SET SIMULATE_CONNTESTFAIL=0
::1=TEST_FAILED,2=TEST_UNREACHED,3=TEST_EXCEEDED_TEST_LIMIT,4=TEST_NEED_BROWSER,5=TEST_SUCCEEDED
SET SIMULATE_NETTEST=0
REM -------------------Initialize Program--------------------
SET THISFILEDIR=%~dp0
SET THISFILENAME=%~n0.bat
SET THISFILENAMEPATH=%~dpnx0
SET INITPARAMS=%1
GOTO :INITIALIZE
REM **************************************************************************
REM *****************************GUI*&*MISC*TOOLS*****************************
REM **************************************************************************
:STATS
%NoECHO%REM ---------------------PROGRAM STATUS-----------------------
%NoECHO%SET statsSleep=%1
%NoECHO%SET STATSSpacer= !
%NoECHO%REM CALL :GETRUNTIME_LENGTH
%NoECHO%SET currently=%currently1%%currently2%%currently3%%currently4%%currently5%
%NoECHO%SET SHOWNETWORK="%NETWORK%"%STATSSpacer%
%NoECHO%SET SHOWcurrently1=%currently1%%STATSSpacer%
%NoECHO%SET SHOWcurrently2=%currently2%%STATSSpacer%
%NoECHO%SET SHOWcurrently3=%currently3%%STATSSpacer%
%NoECHO%SET SHOWcurrently4=%currently4%%STATSSpacer%
%NoECHO%SET SHOWcurrently5=%currently5%%STATSSpacer%
%NoECHO%SET SHOWTimerStatus=%TimerStatus%%STATSSpacer%
%NoECHO%SET SHOWFixMode=
%NoECHO%IF x%Using_Fixes%==x0 SET SHOWFixMode=-Not using fixes-
%NoECHO%IF "%confixed%"=="" SET confixed=0
%NoECHO%REM SET SHOWconfixed= %confixed% in %RUNTIMEL%
%NoECHO%IF NOT "%LastTitle%"=="%THISTITLE%" CALL :CENTERTEXT 74 SHOWTitle ****** %THISTITLE% ******
%NoECHO%IF NOT "%Lastconfixed%"=="%confixed%" CALL :CENTERTEXT 27 SHOWconfixed %confixed%
%NoECHO%SET LastTitle=%THISTITLE%
%NoECHO%SET Lastconfixed=%confixed%
%NoECHO%CLS
%NoECHO% ECHO. ******************************************************************************
%NoECHO% ECHO * *
%NoECHO% ECHO * %SHOWTitle% *
%NoECHO% ECHO * *
%NoECHO% ECHO * http://code.google.com/p/nwconnectionresetter *
%NoECHO% ECHO * *
%NoECHO% ECHO *----------------------------------------------------------------------------*
%NoECHO%IF "%SIMULATE%"=="1" ECHO * *SIMULATION ONLY! Set SIMULATE to 0 to enable functionality* *
%NoECHO%IF "%SIMULATE%"=="1" ECHO *----------------------------------------------------------------------------*
%NoECHO%IF "%CONTINUOUS%"=="1" ECHO * Program started: ^| Continuous Mode ^| Connection Fixes: *
%NoECHO%IF "%CONTINUOUS%"=="1" ECHO * %StartDate% ^| %SHOWFixMode% ^|%SHOWconfixed%*
%NoECHO%IF "%CONTINUOUS%"=="1" ECHO *----------------------------------------------------------------------------*
ECHO * *
%NoECHO%IF NOT "%NETWORK%"=="" ECHO * Connection: %SHOWNETWORK:~0,63%*
%NoECHO%IF NOT "%NETWORK%"=="" ECHO * *
%NoECHO%IF NOT "%currently1%"=="" ECHO * Current State: %SHOWcurrently1:~0,60%*
%NoECHO%IF NOT "%currently2%"=="" ECHO * %SHOWcurrently2:~0,60%*
%NoECHO%IF NOT "%currently3%"=="" ECHO * %SHOWcurrently3:~0,60%*
%NoECHO%IF NOT "%currently4%"=="" ECHO * %SHOWcurrently4:~0,60%*
%NoECHO%IF NOT "%currently5%"=="" ECHO * %SHOWcurrently5:~0,60%*
%NoECHO%IF NOT "%currently%"=="" ECHO * *
%NoECHO%IF NOT "%TimerStatus%"=="" ECHO * %SHOWTimerStatus:~0,75%*
%NoECHO%IF NOT "%TimerStatus%"=="" ECHO * *
ECHO ******************************************************************************
%NoECHO%IF "%SLWMSG%"=="1" CALL :SLEEP %statsSleep%
%NoECHO%IF NOT "%SLWMSG%"=="1" IF NOT "%statsSleep%"=="" CALL :SLEEP %statsSleep%
GOTO :EOF
REM ---------------------END PROGRAM STATUS----------------------
:SLEEP
REM ------------------------PROGRAM SLEEP-------------------------
REM Program sleeps for %1 seconds
IF "%1"=="" SET pN=3
IF NOT "%1"=="" SET pN=%1
PING -n 2 -w 1000 127.0.0.1>NUL 2>&1
PING -n %pN% -w 1000 127.0.0.1>NUL 2>&1
GOTO :EOF
REM ------------------------END PROGRAM SLEEP---------------------
:RESETCURRENTLY
SET currently=
SET currently1=
SET currently2=
SET currently3=
SET currently4=
SET currently5=
SET TimerStatus=
GOTO :EOF
:HEADER
REM Settings header. Used when configuring settings.
%NoECHO%@ECHO OFF
%NoECHO%IF NOT "%LastTitle%"=="%THISTITLE%" CALL :CENTERTEXT 74 SHOWTitle ****** %THISTITLE% ******
%NoECHO%SET LastTitle=%THISTITLE%
SET DONEINIT=::
%NoECHO%CLS
%NoECHO%ECHO ******************************************************************************
%NoECHO%ECHO * *
%NoECHO%ECHO * %SHOWTitle% *
%NoECHO%ECHO * *
%NoECHO%ECHO ******************************************************************************
%NoECHO%ECHO.
GOTO :EOF
:CENTERTEXT
%DONEINIT%%NoECHO%ECHO..........
SET TTLSPACE=%1
SET VAR2SET=%2
SET TEXT=
SET INCNUM=0
SET NUMCHECK=
SET HALFSPACE=
SET PARAMSPACE=
:CENTERTEXT_GETALLTEXT
IF NOT "%3"=="" SET TEXT=%TEXT%%PARAMSPACE%%3
IF NOT "%3"=="" SET PARAMSPACE= &SHIFT&GOTO :CENTERTEXT_GETALLTEXT
%DONEINIT%%NoECHO%ECHO...........
CALL :StrLength STRLEN %TEXT%
SET /A HALFSPACE=(TTLSPACE-STRLEN)/2
:ADDSPACEFRONT
SET /A INCNUM+=1
SET TEXT= %TEXT%
IF NOT %INCNUM% GEQ %HALFSPACE% GOTO :ADDSPACEFRONT
%DONEINIT%%NoECHO%ECHO..............
SET INCNUM=0
:ADDSPACEBACK
SET /A INCNUM+=1
SET TEXT=%TEXT%
IF NOT %INCNUM% GEQ %HALFSPACE% GOTO :ADDSPACEBACK
SET /A NUMCHECK=(TTLSPACE-STRLEN)%%2
IF %NUMCHECK% GEQ 1 SET TEXT= %TEXT%
SET %VAR2SET%=%TEXT%
GOTO :EOF
:StrLength
::StrLength(retVal,string)
SET PARAMSPACE=
SET StrLenVar=%1
:StrLength_GETALLTEXT
IF NOT "%2"=="" SET #=%#%%PARAMSPACE%%2
IF NOT "%2"=="" SET PARAMSPACE= &SHIFT&GOTO :StrLength_GETALLTEXT
%DONEINIT%%NoECHO%ECHO............
set length=0
:stringLengthLoop
SET #def=0
IF DEFINED # SET #def=1
IF %#def%==1 SET #=%#:~1%
IF %#def%==1 SET /A length += 1
IF %#def%==1 GOTO :stringLengthLoop
%DONEINIT%%NoECHO%ECHO.............
SET "%StrLenVar%=%length%"
GOTO :EOF
:ToLower
FOR %%i IN ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i" "J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r" "S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z") DO CALL SET "%1=%%%1:%%~i%%"
GOTO:EOF
:GET_Randomfilename
SET filevar=%1
SET ext=%2
SET %filevar%=temp%RANDOM:~0,7%%ext%
IF EXIST "%THISFILEDIR%!%filevar%!" GOTO :GET_Randomfilename
GOTO :EOF
:GET_Randomfoldername
SET foldervar=%1
SET %foldervar%=temp%RANDOM:~0,7%
IF EXIST "%THISFILEDIR%!%foldervar%!"NUL GOTO :GET_Randomfoldername
GOTO :EOF
:GETRUNTIME_LENGTH
SET cYEAR=%DATE:~-4%
SET cMONTH=%DATE:~4,2%
SET cDAY=%DATE:~7,2%
SET cHOUR=%TIME:~0,2%
SET cMINUTE=%TIME:~3,2%
SET cSECOND=%TIME:~6,2%
IF NOT %cYEAR% GEQ 10 SET cYEAR=%cYEAR:~1,1%
IF NOT %cMONTH% GEQ 10 SET cMONTH=%cMONTH:~1,1%
IF NOT %cDAY% GEQ 10 SET cDAY=%cDAY:~1,1%
IF NOT %cHOUR% GEQ 10 SET cHOUR=%cHOUR:~1,1%
IF NOT %cMINUTE% GEQ 10 SET cMINUTE=%cMINUTE:~1,1%
IF NOT %cSECOND% GEQ 10 SET cSECOND=%cSECOND:~1,1%
SET /A LeapYear=cYEAR%%4
IF %cSECOND% LSS %iSECOND% (
SET /A cMINUTE-=1
SET /A cSECOND+=60
)
IF %cMINUTE% LSS %iMINUTE% (
SET /A cHOUR-=1
SET /A cMINUTE+=60
)
IF %cHOUR% LSS %iHOUR% (
SET /A cDAY-=1
SET /A cHOUR+=24
)
IF NOT %cDAY% LSS %iDAY% GOTO :AFTcDAYCHECK
SET /A TMPMO=iMONTH
SET /A TMPNUM=iMONTH%%2
IF %cMONTH% LEQ 7 IF %TMPNUM%==1 SET MODAYS=31
IF %cMONTH% LEQ 7 IF %TMPNUM%==0 SET MODAYS=30
IF %cMONTH% GEQ 8 IF %TMPNUM%==0 SET MODAYS=31
IF %cMONTH% GEQ 8 IF %TMPNUM%==1 SET MODAYS=30
IF %cMONTH%==2 SET MODAYS=28
IF %cMONTH%==2 IF %LeapYear%==1 SET MODAYS=29
SET /A cMONTH-=1
SET /A cDAY+=MODAYS
:AFTcDAYCHECK
IF %cMONTH% LSS %iMONTH% (
SET /A cYEAR-=1
SET /A cMONTH+=12
)
SET /A cYEAR=cYEAR-iYEAR
SET /A cMONTH=cMONTH-iMONTH
SET /A cDAY=cDAY-iDAY
SET /A cHOUR=cHOUR-iHOUR
SET /A cMINUTE=cMINUTE-iMINUTE
SET /A cSECOND=cSECOND-iSECOND
IF %cSECOND% LSS 10 SET cSECOND=0%cSECOND%
IF %cMINUTE% LSS 10 SET cMINUTE=0%cMINUTE%
SET RUNTIMEL=
IF NOT %cYEAR%==0 SET RUNTIMEL=%cYEAR% yr
IF NOT %cMONTH%==0 SET RUNTIMEL=%RUNTIMEL%%cMONTH% mo
IF NOT %cDAY%==0 SET RUNTIMEL=%RUNTIMEL%%cDAY% day
SET RUNTIMEL=%RUNTIMEL%%cHOUR%:%cMINUTE%:%cSECOND%
GOTO :EOF
REM -----------------END INITIALIZE PROGRAM------------------
:MAIN_START
SET NETWORK_FOUNDINVALID=1
REM ------------------TO FIX OR NOT TO FIX-------------------
IF %Using_Fixes%==0 GOTO :CHECK_CONNECTION_ONLY
REM ----------------END TO FIX OR NOT TO FIX-----------------
REM -------------INITIAL NETWORK CONNECTION TEST-------------
REM BRANCH (SUCCESS || FIX)
REM Determine if connection needs to be fixed
IF %SKIP_INITIAL_NTWK_TEST%==1 GOTO :MAINNETTEST_FAIL
REM TEST CONNECTION AND INTERNET ACCESS
CALL :TEST_CONNECTION
IF %isConnected%==0 GOTO :MAINCONNTEST_FAIL
IF %isConnected%==1 GOTO :MAINCONNTEST_SUCCESS
:MAINCONNTEST_SUCCESS
CALL :TEST_INTERNET isConnected
IF %isConnected%==0 GOTO :MAINNETTEST_FAIL
IF %isConnected%==1 GOTO :SUCCESS
IF %isConnected%==2 GOTO :MAINNETTEST_UNREACH
:MAINCONNTEST_FAIL
CALL :DISCONNECTION_DETECTED
SET /A CONNFIX+=1
IF %CONNFIX% GTR %NUMCONNFIXES% GOTO :FAILED
CALL :CONNFIX%CONNFIX%
GOTO :MAIN_START
:MAINNETTEST_FAIL
CALL :DISCONNECTION_DETECTED
SET /A NETFIX+=1
IF %NETFIX% GTR %NUMNETFIXES% GOTO :FAILED
CALL :NETFIX%NETFIX%
GOTO :MAIN_START
:MAINNETTEST_UNREACH
IF NOT "%USE_RESET_ROUTE_TABLE%"=="1" GOTO :MAINNETTEST_FAIL
CALL :DISCONNECTION_DETECTED
SET ROUTEFIX+=1
IF %ROUTEFIX% GTR 1 GOTO :FAILED
CALL :FIXUNREACHABLE
GOTO :MAIN_START
REM -----------END INITIAL NETWORK CONNECTION TEST----------
:TEST_CONNECTION
REM ------------------TEST INTERNET CONNECTION-------------------
REM RETURN (isConnected= (1 || 0) )
CALL :RESETCURRENTLY
SET conchks=0
SET maxconchks=51
SET isConnected=0
SET currently2=
IF %SIMULATE%==1 IF %SIMULATE_CONNTESTFAIL%==1 GOTO :TEST_CONNECTION_FAILED
IF %SIMULATE%==1 IF %SIMULATE_CONNTESTFAIL%==0 SET isConnected=1&GOTO :EOF
:TEST_CONNECTION_CHECK
SET currently1=Checking for connectivity...
IF %conchks% GTR 0 SET currently2=[Currently Disconnected]
SET TimerStatus=
CALL :STATS
%NoECHO%IF %SHOW_ADVANCED_TESTING%==1 ECHO Checks: %conchks%
IF "%NETWORK_IsMBN%"=="0" FOR /F "delims=" %%a IN ('NETSH INTERFACE SHOW INTERFACE "%NETWORK%"') DO @SET connect_test=%%a
IF "%NETWORK_IsMBN%"=="0" ECHO %connect_test% |FIND "Disconnected" >NUL
IF "%NETWORK_IsMBN%"=="0" IF ERRORLEVEL 1 SET isConnected=1&GOTO :EOF
IF "%NETWORK_IsMBN%"=="1" SET TC_MBN_ThisLine=0
IF "%NETWORK_IsMBN%"=="1" SET isConnected=0
IF "%NETWORK_IsMBN%"=="1" FOR /F "tokens=* delims=" %%a IN ('NETSH MBN SHOW INTERFACES') DO CALL :TEST_CONNECTION_CHECK_MBNPARSE %%a
REM IF "%NETWORK_IsMBN%"=="1" FOR /F "tokens=* delims=" %%a IN (C:\output.txt) DO CALL :TEST_CONNECTION_CHECK_MBNPARSE %%a
IF "%NETWORK_IsMBN%"=="1" IF "%isConnected%"=="1" GOTO :EOF
SET /A conchks+=1
IF %conchks% GEQ %maxconchks% GOTO :TEST_CONNECTION_FAILED
GOTO :TEST_CONNECTION_CHECK
:TEST_CONNECTION_CHECK_MBNPARSE
SET TC_MBN_Line=%*
FOR /F "tokens=1,2 delims=:" %%b IN ("%TC_MBN_Line%") DO SET TC_MBN_LineA=%%b&SET TC_MBN_LineB=%%c
IF "%TC_MBN_LineA%"=="" GOTO :EOF
ECHO %TC_MBN_LineA%|FIND "Name">NUL
SET TC_MBN_ERR=%ERRORLEVEL%
IF %TC_MBN_ERR%==0 ECHO "%TC_MBN_LineB%"|FIND "%NETWORK%">NUL
IF %TC_MBN_ERR%==0 IF NOT ERRORLEVEL 1 SET TC_MBN_ThisLine=1&GOTO :EOF
IF %TC_MBN_ERR%==0 SET TC_MBN_ThisLine=0&GOTO :EOF
IF %TC_MBN_ThisLine%==0 GOTO :EOF
ECHO %TC_MBN_LineA%|FIND "State">NUL
IF ERRORLEVEL 1 GOTO :EOF
ECHO %TC_MBN_LineB%|FIND "Not">NUL
IF ERRORLEVEL 1 SET isConnected=1
GOTO :EOF
:TEST_CONNECTION_FAILED
SET currently1=Connectivity test failed
SET currently2=[Currently Disconnected]
SET TimerStatus=
CALL :STATS
SET isConnected=0
GOTO :EOF
:TEST_INTERNET
SET main_tests=0
SET MaxStalls=10
SET NumStalls=0
:TEST_INIT
SET currently1=Testing Internet Connection...
SET currently2=
SET TimerStatus=
CALL :STATS
IF %SIMULATE%==1 IF %SIMULATE_NETTEST%==1 CALL :TEST_SET_TIME1&GOTO :TEST_FAILED
IF %SIMULATE%==1 IF %SIMULATE_NETTEST%==2 CALL :TEST_SET_TIME1&GOTO :TEST_UNREACHED
IF %SIMULATE%==1 IF %SIMULATE_NETTEST%==3 CALL :TEST_SET_TIME1&GOTO :TEST_EXCEEDED_TEST_LIMIT
IF %SIMULATE%==1 IF %SIMULATE_NETTEST%==4 CALL :TEST_SET_TIME1&GOTO :TEST_NEED_BROWSER
IF %SIMULATE%==1 IF %SIMULATE_NETTEST%==5 CALL :TEST_SET_TIME1&GOTO :TEST_SUCCEEDED
::Initialize Net Test
SET testwebsitenum=-1
CALL :TEST_CHANGETESTSITE
SET founds=0
SET times=0
SET nots=0
SET unreaches=0
SET totalTests=0
SET fluke_test_eliminator=5
SET maxTestLimit=15
SET /A NumStalls+=1
SET T_MILI_SMALLEST=300
::PING TEST
:TEST_TESTING
FOR /F "delims=" %%a IN ('PING -n 1 "%testwebsite%"') DO @SET ping_test=%%a
ECHO %ping_test% |FIND "request could not find" >NUL
IF NOT ERRORLEVEL 1 GOTO :TEST_NOT_CONNECTED
ECHO %ping_test% |FIND "Unreachable" >NUL
IF NOT ERRORLEVEL 1 GOTO :TEST_UNREACHABLE
ECHO %ping_test% |FIND "Minimum " >NUL
IF NOT ERRORLEVEL 1 GOTO :TEST_CONNECTED
GOTO :TEST_TIMED_OUT
REM ---------TEST-TOOLS------------
:TEST_INC_TOTALTESTS
SET /A totalTests+=1
SET SHOWttlTests=%totalTests% .
GOTO :EOF
:TEST_SET_TIME1
SET T1_DATE=%DATE%
FOR /F "tokens=1-4* DELIMS=:." %%t IN ("%TIME%") DO SET T1_HR=%%t&SET T1_MIN=%%u&SET T1_SEC=%%v&SET T1_MIL=%%w
SET /A T1_TTLTIME=T1_MIL+(T1_SEC*100)+(T1_MIN*6000)+(T1_HR*360000)
GOTO :EOF
:TEST_CHANGETESTSITE
REM Microsoft Sites do NOT work!
SET TTLSITES=9
IF "%testwebsitenum%"=="-1" (
SET /A testwebsitenum=TTLSITES*%RANDOM%/32768+1
) ELSE (
IF %testwebsitenum% GEQ %TTLSITES% (
SET testwebsitenum=1
) ELSE (
SET /A testwebsitenum+=1
)
)
IF "%testwebsitenum%"=="1" SET testwebsite=www.facebook.com
IF "%testwebsitenum%"=="2" SET testwebsite=www.google.com
IF "%testwebsitenum%"=="3" SET testwebsite=www.linkedin.com
IF "%testwebsitenum%"=="4" SET testwebsite=www.yahoo.com
IF "%testwebsitenum%"=="5" SET testwebsite=www.apple.com
IF "%testwebsitenum%"=="6" SET testwebsite=www.youtube.com
IF "%testwebsitenum%"=="7" SET testwebsite=www.ask.com
IF "%testwebsitenum%"=="8" SET testwebsite=www.baidu.com
IF "%testwebsitenum%"=="9" SET testwebsite=www.wikipedia.org
IF "%testwebsite%"=="" GOTO :TEST_CHANGETESTSITE
GOTO :EOF
REM --------END-TEST-TOOLS---------
REM ---------PING-RESULTS----------
:TEST_CONNECTED
CALL :TEST_INC_TOTALTESTS
IF %SHOW_ADVANCED_TESTING%==1 ECHO %SHOWttlTests:~0,2%: Connect Success (%testwebsite%)
SET /A founds+=1
SET unreaches=0
SET times=0
SET nots=0
IF %founds% GEQ %fluke_test_eliminator% GOTO :TEST_SUCCEEDED
GOTO :TEST_TESTING
:TEST_NOT_CONNECTED
CALL :TEST_INC_TOTALTESTS
IF %nots%==0 CALL :TEST_SET_TIME1
IF %SHOW_ADVANCED_TESTING%==1 ECHO %SHOWttlTests:~0,2%: Could not connect (%testwebsite%)
CALL :TEST_CHANGETESTSITE
SET /A nots+=1
SET unreaches=0
SET founds=0
SET times=0
IF %nots% GEQ %fluke_test_eliminator% GOTO :TEST_FAILED
GOTO :TEST_TESTING
:TEST_UNREACHABLE
CALL :TEST_INC_TOTALTESTS
IF %unreaches%==0 CALL :TEST_SET_TIME1
IF %SHOW_ADVANCED_TESTING%==1 ECHO %SHOWttlTests:~0,2%: Location Unreachable (%testwebsite%)
CALL :TEST_CHANGETESTSITE
SET /A unreaches+=1
SET founds=0
SET nots=0
SET times=0
IF %nots% GEQ %fluke_test_eliminator% GOTO :TEST_UNREACHED
GOTO :TEST_TESTING
:TEST_TIMED_OUT
CALL :TEST_INC_TOTALTESTS
IF %times%==0 CALL :TEST_SET_TIME1
IF %SHOW_ADVANCED_TESTING%==1 ECHO %SHOWttlTests:~0,2%: Request Timed Out (%testwebsite%)
CALL :TEST_CHANGETESTSITE
SET /A times+=1
SET unreaches=0
SET founds=0
SET nots=0
IF %TREAT_TIMEOUTS_AS_DISCONNECT%==1 IF %times% GEQ %fluke_test_eliminator% GOTO :TEST_FAILED
IF %TREAT_TIMEOUTS_AS_DISCONNECT%==0 IF %times% GEQ %fluke_test_eliminator% GOTO :TEST_NEED_BROWSER
IF %totalTests% GEQ %maxTestLimit% GOTO :TEST_EXCEEDED_TEST_LIMIT
GOTO :TEST_TESTING
REM ---------END-PING-RESULTS----------
REM ---------TEST-RESULTS-------------
:TEST_FAILED
REM DEBUGGING || FAILED A TEST
SET T2_DATE=%DATE%
IF NOT "%T1_DATE%"=="%T2_DATE%" GOTO :TEST_INTERNET
FOR /F "tokens=1-4* DELIMS=:." %%t IN ("%TIME%") DO SET T2_HR=%%t&SET T2_MIN=%%u&SET T2_SEC=%%v&SET T2_MIL=%%w
SET /A T2_TTLTIME=T2_MIL+(T2_SEC*100)+(T2_MIN*6000)+(T2_HR*360000)
SET /A T_TIMEPAST=T2_TTLTIME-T1_TTLTIME
IF %NumStalls%==1 SET TH=st
IF %NumStalls%==2 SET TH=nd
IF %NumStalls%==3 SET TH=rd
IF %NumStalls% GEQ 4 SET TH=th
IF %SHOW_ADVANCED_TESTING%==1 IF %T_TIMEPAST% LSS %T_MILI_SMALLEST% ECHO Test Too Fast Detected! Stalling...(%NumStalls%%TH% of Max:%MaxStalls%)
IF %T_TIMEPAST% LSS %T_MILI_SMALLEST% IF NOT %NumStalls% GEQ %MaxStalls% CALL :SLEEP&GOTO :TEST_INIT
SET /A main_tests=main_tests+1
IF %SLWMSG%==1 CALL :SLEEP
SET currently1=Internet Connection not detected
SET currently2=
SET TimerStatus=
CALL :STATS
SET isConnected=0
GOTO :EOF
:TEST_UNREACHED
IF %SLWMSG%==1 CALL :SLEEP
IF NOT %SLWMSG%==1 IF %SHOW_ADVANCED_TESTING%==1 CALL :SLEEP 1
SET currently1=Target sites are unreachable.
SET currently2=
SET TimerStatus=
CALL :STATS 3
SET isConnected=2
GOTO :EOF
:TEST_EXCEEDED_TEST_LIMIT
IF %SLWMSG%==1 CALL :SLEEP
IF NOT %SLWMSG%==1 IF %SHOW_ADVANCED_TESTING%==1 CALL :SLEEP 1
SET currently1=Unable to varify internet connectivity. This is a
SET currently2=poor quality connection. Internet browsing may be slow.
SET TimerStatus=
CALL :STATS 3
SET isConnected=1
GOTO :EOF
:TEST_NEED_BROWSER
IF %SLWMSG%==1 CALL :SLEEP
IF NOT %SLWMSG%==1 IF %SHOW_ADVANCED_TESTING%==1 CALL :SLEEP 1
SET currently1=Unable to varify internet connectivity. You may need
SET currently2=to long in via a browser for full network access.
SET TimerStatus=
CALL :STATS 3
SET isConnected=1
GOTO :EOF
:TEST_SUCCEEDED
IF %SLWMSG%==1 CALL :SLEEP
IF NOT %SLWMSG%==1 IF %SHOW_ADVANCED_TESTING%==1 CALL :SLEEP 1
SET isConnected=1
GOTO :EOF
REM ---------TEST-RESULTS-------------
REM ----------------END TEST INTERNET CONNECTION-----------------
:DISCONNECTION_DETECTED
IF %SETNFileDir%==TEMP GOTO :DISCONNECTION_DETECTED_NOLOG
SET MyDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
SET MyDate=%MyDate: =0%
SET MyTime=%TIME: =0%
TYPE NUL>>"%SETNFileDir%log.csv"
IF "%USELOGGING%"=="1" IF NOT %ProgramMustFix%0==10 (ECHO %NETWORK% , Disconnected , %MyDate% , %MyTime%)>>"%SETNFileDir%log.csv"
:DISCONNECTION_DETECTED_NOLOG
SET ProgramMustFix=1
GOTO :EOF
:RECONNECTION_DETECTED
IF %SETNFileDir%==TEMP GOTO :RECONNECTION_DETECTED_NOLOG
SET MyDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
SET MyDate=%MyDate: =0%
TYPE NUL>>"%SETNFileDir%log.csv"
IF "%USELOGGING%"=="1" (ECHO %NETWORK% , Reconnected , %MyDate% , %MyTime%)>>"%SETNFileDir%log.csv"
:RECONNECTION_DETECTED_NOLOG
SET ProgramMustFix=0
IF "%confixed%"=="" SET confixed=0
SET /A confixed+=1
GOTO :EOF
REM ------------------FIX INTERNET CONNECTION--------------------
REM BRANCH (SUCCESS || FAILED)
REM Call the different methods of fixing
REM This allows for different fixes to be added later
REM In order to add more fixes, NUMCONNFIXES and NUMNETFIXES must
REM be raised (if the fix pertains to them).
REM *****RESET NETWORK ADAPTER FAST*****
:CONNFIX1
:NETFIX1
IF "%USE_NETWORK_RESET_FAST%"=="1" CALL :FIX_RESET_NETWORK_FAST
GOTO :EOF
REM *****RESET IP ADDRESS*****
:CONNFIX2
:NETFIX2
IF "%USE_IP_RESET%"=="1" CALL :FIX_RESET_IP
GOTO :EOF
REM *****RESET NETWORK ADAPTER SLOW*****
:NETFIX3
IF "%USE_NETWORK_RESET%"=="1" CALL :FIX_RESET_NETWORK
GOTO :EOF
REM *****RESET ROUTE TABLE*****
:FIXUNREACHABLE
IF "%USE_RESET_ROUTE_TABLE%"=="1" ROUTE -F
GOTO :EOF
REM -----------------END FIX INTERNET CONNECTION------------------
:FIX_RESET_IP
REM -------------------FIX: RESET IP ADDRESS----------------------
REM Fix internet connection by reseting the IP address
SET currently1=Releasing IP Address
SET currently2=*May take a couple minutes*
SET TimerStatus=
CALL :STATS
REM Release IP Address
IPCONFIG /RELEASE >NUL 2>&1
REM Flush DNS Cache
SET currently1=Flushing DNS Cache
SET currently2=
SET TimerStatus=
CALL :STATS
IPCONFIG /FLUSHDNS >NUL 2>&1
REM Renew IP Address
SET currently1=Renewing IP Address
SET currently2=*May take a couple minutes*
SET TimerStatus=
CALL :STATS
IPCONFIG /RENEW >NUL 2>&1
REM CANNOT TEST HERE
REM Checking network connection here causes unwanted recursion
GOTO :EOF
REM -----------------END FIX: RESET IP ADDRESS--------------------
:FIX_RESET_NETWORK_FAST
REM -------------FIX: RESET NETWORK CONNECTION FAST---------------
REM Disable Network, Enable Network
CALL :DISABLE_NW
CALL :ENABLE_NW
REM CANNOT TEST HERE
REM Checking network connection here causes unwanted recursion
GOTO :EOF
REM -----------END FIX: RESET NETWORK CONNECTION FAST-------------
:FIX_RESET_NETWORK
REM ---------------FIX: RESET NETWORK CONNECTION------------------
REM Disable Network, Wait, Enable Network
REM Disable network connection
CALL :DISABLE_NW
SET currently1=Waiting to re-enable [%NETWORK%]
SET currently2=
SET TimerStatus=
REM Wait specified time
SET delaymins=%MINUTES%
CALL :WAIT
REM Enable network connection
CALL :ENABLE_NW
REM CANNOT TEST HERE
REM Checking network connection here causes unwanted recursion
GOTO :EOF
REM -------------END FIX: RESET NETWORK CONNECTION----------------
:WAIT
SETLOCAL
REM -----------------------PROGRAM TIMER--------------------------
REM ******INITIALIZE TIMER*****
REM Calculate total time
SET /A PINGS="(delaymins*60)/TIMER_REFRESH_RATE"
SET /A TTLSCNDS="PINGS*TIMER_REFRESH_RATE"
SET /A HOURS="(TTLSCNDS/3600)"
SET /A MINUTES2="(TTLSCNDS-(HOURS*3600))/60"
SET /A SECONDS="TTLSCNDS-((HOURS*3600)+(MINUTES2*60))"
REM Set HOURS to "" or "##:"
REM (always 2 digits or nothing)
IF %HOURS%==0 (
SET HOURS=
) ELSE (
SET HOURS=%HOURS%:
)
REM Set MINUTES2 to "","##:", "00:", or "0#:"
REM (always 2 digits or nothing)
REM (always 2 digits if HOURS>0)
IF %MINUTES2%==0 (
IF "%HOURS%"=="" (
SET MINUTES2=
) ELSE (
SET MINUTES2=00:
)
) ELSE (
SET MINUTES2=%MINUTES2%:
)
REM Set SECONDS to "##" or "0#"
REM (always 2 digits)
IF %SECONDS% LEQ 9 SET SECONDS=0%SECONDS%
REM Set Ticker to 0
SET ticker=0
REM ****END INITIALIZE TIMER***
:WAITING
REM *****TICKING TIMER*****
REM Calculate REM aining time
SET /A left="PINGS-ticker"
SET /A ttlscndslft="left*TIMER_REFRESH_RATE"
SET /A hrs="ttlscndslft/3600"
SET /A mins="(ttlscndslft-(hrs*3600))/60"
SET /A scnds="(ttlscndslft-((hrs*3600)+(mins*60)))"
REM Bump ticker
SET /A ticker+=1
REM Set hrs to "","##:", or "0#:"
REM (always 2 digits or nothing)
IF %hrs%==0 (
SET hrs=
) ELSE (
SET hrs=%hrs%:
)
REM Set mins to "","##:", "00:", or "0#:"
REM (always 2 digits or nothing)
REM (always 2 digits if HOURS>0)
IF %mins%==0 (
IF "%hrs%"=="" (
SET mins=
) ELSE (
SET mins=00:
)
) ELSE (
IF "%hrs%"=="" (
SET mins=%mins%:
) ELSE (
IF %mins% LEQ 9 (
SET mins=0%mins%:
) ELSE (
SET mins=%mins%:
)
)
)
REM Set SECONDS to "##" or "0#"
REM (always 2 digits)
IF %scnds% LEQ 9 SET scnds=0%scnds%
REM Update TimeStamp
SET TimerStatus=Time Left: %hrs%%mins%%scnds% of %HOURS%%MINUTES2%%SECONDS%
REM Display updated TimeStamp
CALL :STATS
CALL :SLEEP %TIMER_REFRESH_RATE%
REM Cycle through "WAITING" again if waiting time
REM has not been reached
IF %ticker% LEQ %PINGS% GOTO :WAITING
ENDLOCAL
SET has_tested_ntwk_name_recent=0
GOTO :EOF
REM ---------------------END PROGRAM TIMER------------------------
:DISABLE_NW
REM -----------------DISABLE NETWORK CONNECTION-------------------
REM Determine OS and disable via a compatible method
SET currently1=Disabling [%NETWORK%]...
SET currently2=
SET TimerStatus=
CALL :STATS
IF %ONLY_ONE_NETWORK_NAME_TEST%==0 CALL :TEST_NETWORK_NAME
IF %winVistaOrNewer%==1 NETSH INTERFACE SET INTERFACE "%NETWORK%" DISABLE
IF %winVistaOrNewer%==0 CALL :TOGGLECONNECTION_OLD_OS DIS
SET currently1=[%NETWORK%] Disabled
SET currently2=
SET TimerStatus=
CALL :STATS
GOTO :EOF
REM ---------------END DISABLE NETWORK CONNECTION-----------------
:ENABLE_NW
REM ------------------ENABLE NETWORK CONNECTION-------------------
REM Determine OS and enable via a compatible method
SET currently1=Enabling [%NETWORK%]
SET currently2=
SET TimerStatus=
CALL :STATS
REM TEST_NETWORK_NAME (EXIT || RETURN)
IF %ONLY_ONE_NETWORK_NAME_TEST%==0 CALL :TEST_NETWORK_NAME
IF %winVistaOrNewer%==1 NETSH INTERFACE SET INTERFACE "%NETWORK%" ENABLE
IF %winVistaOrNewer%==0 CALL :TOGGLECONNECTION_OLD_OS EN
SET currently1=[%NETWORK%] Enabled
SET currently2=
SET TimerStatus=
CALL :STATS
GOTO :EOF
REM ----------------END ENABLE NETWORK CONNECTION-----------------
:TOGGLECONNECTION_OLD_OS
REM ----------------DISABLE/ENABLE CONNECTION FOR WINXP------------------
REM No known way to disable/enable from cmd line. Instead, we must