Advertisement
L1ttl3J1m

Test list of IP addresses

Jan 12th, 2017
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #########################################################
  2. #                                                       #
  3. #       This script will do the following;              #
  4. #        - Read in a list of IP addresses               #
  5. #        - Strip off any port numbers                   #
  6. #        - Remove duplicate IP addresses                #
  7. #        - Test the connection to each IP               #
  8. #        - Report the connection speed to each one      #
  9. #                                                       #
  10. #########################################################
  11.  
  12. # Prepare the results file
  13. "IP Address, response time" | out-file -FilePath "c:\temp\results.csv"  -encoding utf8
  14.  
  15. # Create the array for holding the list of addresses.
  16. $LIST = new-object system.collections.arraylist
  17.  
  18. # Read in the list of addresses
  19. foreach ($line in get-content c:\temp\addresses.txt) {$LIST.add("$line")}
  20.  
  21. # Remove any port suffixes
  22. $count=0;while ($count -lt $LIST.count){$LIST[$count]=$LIST[$count].split(":")[0];$count++}
  23.  
  24. # Remove duplicates
  25. $count=0
  26. while ($count -lt $LIST.count)
  27. {
  28.         if ($list[$count] -eq $list[$count+1])
  29.             {
  30.               $list.removeat($count+1)
  31.               $count++
  32.             }
  33.             else
  34.             {
  35.             $count++
  36.             }
  37. }
  38.  
  39.  
  40. # Test each IP
  41. foreach ($line in $LIST)
  42. {
  43.     $test=test-connection -count 1 -quiet $line
  44.     if ($test -eq $False)
  45.     {
  46.         write-host -foregroundcolor yellow $line,Failed
  47.         "$line`tFailed" | out-file -append -filepath "c:\temp\results.csv" -encoding utf8
  48.     }
  49.  else
  50.     {
  51.     $test=test-connection -count 1 $line
  52.     $responsetime=$test.responsetime
  53.     write-host $line, $responsetime
  54.     write-output "$line`t$responsetime" | out-file -append -filepath "c:\temp\results.csv" -encoding utf8
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement