Advertisement
Guest User

internet connection tester script v2

a guest
May 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $dnsstatus = 1
  2. $pingstatus = 1
  3. $localstatus = 1
  4. $filelocation = 'C:/log/internetlog.txt'
  5.  
  6. $ScriptBlock = {
  7. param($addr)
  8. Test-Connection $addr -Quiet -count 1 -timetolive 100
  9. }
  10.  
  11.  while(1){
  12.  
  13.     Start-Job $ScriptBlock -argumentlist "google.com"
  14.     Start-Job $ScriptBlock -argumentlist "1.1.1.1"
  15.     Start-Job $ScriptBlock -argumentlist "192.168.1.1"
  16.    
  17.    
  18.     start-sleep -m 50
  19.    
  20.     while (Get-Job -state "Running") {start-sleep -m 10}
  21.    
  22.     ($dnstest, $pingtest, $localtest) = Get-Job | Receive-job
  23.     get-job | remove-job
  24.    
  25.     $date=Get-Date
  26.     if ($dnstest -and !$dnsstatus){
  27.         $text = 'DNS resolved connections resumed working at ' + $date
  28.         $text >> $filelocation
  29.         $dnsstatus = 1
  30.         }
  31.     if (!$dnstest -and $dnsstatus){
  32.         $text = 'DNS resolved connections stopped working at ' + $date
  33.         $text >> $filelocation
  34.         $dnsstatus = 0
  35.         }
  36.     if ($pingtest -and !$pingstatus){
  37.         $text = 'IP resolved connections resumed working at ' + $date
  38.         $text >> $filelocation
  39.         $pingstatus = 1
  40.         }
  41.     if (!$pingtest -and $pingstatus){
  42.         $text = 'IP resolved connections stopped working at ' + $date
  43.         $text >> $filelocation
  44.         $pingstatus = 0
  45.         }
  46.     if ($localtest -and !$localstatus){
  47.         $text = 'local connections resumed working at ' + $date
  48.         $text >> $filelocation
  49.         $localstatus = 1
  50.         }
  51.     if (!$localtest -and $localstatus){
  52.         $text = 'IP resolved connections stopped working at ' + $date
  53.         $text >> $filelocation
  54.         $localstatus = 0
  55.         }
  56. Start-Sleep -s 10
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement