PERL   31

echoping.pl

Guest on 23rd September 2022 12:50:07 AM

  1. #!/usr/bin/perl -w
  2. #
  3. # It is my first (dirty) perl script. GPL2.
  4. # It use echoping to test responce time of servers for http, https, smtp and echo protocols
  5. #  version 0.2
  6. # Please e-mail me optimisations...
  7. # Sbastien Desse : sdesse@euresys.fr
  8. #
  9. # sysntax : echoping.pl <number of tests> <protocol> <URL>
  10. #       number of tests         > 1
  11. #       protocol                = http | ssl | smtp | echo
  12. #       URL                     = @IP | FQDN
  13. #
  14. #
  15.  
  16. @ARGV == 3 or die "Syntax : echoping.pl <number of tests> <protocol> <URL>\n";
  17.  
  18.  
  19. if (($ARGV[0] =~ m/^\d+$/) and ($ARGV[0] > 1) and  ($ARGV[0] < 11)) {
  20.         $NumberOfTests = "-n $ARGV[0]";
  21. } else {
  22.         $NumberOfTests = "-n 5";
  23. }
  24.  
  25. if ($ARGV[1] =~ m/http/i) {
  26.         $Protocol = "-h /";
  27. # Need echoping compiled with SSL support
  28. #} elsif ($ARGV[1] =~ m/ssl/i) {
  29. #       $Protocol = "-C -h /";
  30. } elsif ($ARGV[1] =~ m/smtp/i) {
  31.         $Protocol = "-S";
  32. } elsif ($ARGV[1] =~ m/echo/i) {
  33.         $Protocol = "";
  34. } else {
  35.         $Protocol = "-h /";
  36. }      
  37.  
  38. $Url = $ARGV[2];
  39.  
  40. ($Min,$Max,$Average) = (`echoping $NumberOfTests $Protocol $Url` =~ m/Min.*(\d+\.\d+).*\nMax.*(\d+\.\d+).*\nAverage.*(\d+\.\d+)/);
  41.  
  42. print "$Min $Max $Average";

Raw Paste


Login or Register to edit or fork this paste. It's free.