+ Reply to Thread
Results 1 to 2 of 2

Thread: Packet Loss Perl Script

  1. #1
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Packet Loss Perl Script

    I had to write a program that determined the packet loss of our switches and displayed the results only if the packet loss was more than 0%. However, what was needed was a GUI (which I later wrote in C#) but at this time I had created a shell script. Below is the code:


    1) Add the IPs to $host[x] that you want to ping or remove the for loop and use the argument $host variable to ping.

    2) Uncomment these lines to see all ping results. Those that failed will show in Yellow:

    Code:
    #       else {
    #               print "IP: $h loss:$loss\n";
    #       }

    Complete Script:

    Code:
    #!/usr/bin/perl
    
    # For Testing use an argument
    #$host = $ARGV[0];
    
    # Define our Hosts
    $host[0] = "msn.com";
    $host[1] = "google.com";
    
    # Loop through our hosts and ping
    foreach $h(@host) {
            $ping = `/bin/ping -c 2 -n -q $h`;
    
            my ($loss) = ($ping =~ /(\d+)%/g);
            my ($one,$rtt) = ($ping =~ /(\d+\.\d+)\//g);
    
            if ($rtt eq "") {
                    $rtt = 0;
                    $loss = 100;
            }
    
            # Display ping loss
            if ($loss > 0) {
                    print "\033[33;1mIP: $h Ping-Loss: $loss%\033[0m\n";
            }
    #       else {
    #               print "IP: $h loss:$loss\n";
    #       }
    }

  2. #2
    Programmer icepack is on a distinguished road icepack's Avatar
    Join Date
    Jul 2006
    Location
    North Carolina
    Posts
    115
    you should put your name and such in the source

    i'm writing an test automation system for my research team, we've been testing high-end routers.

    we were just at Cisco Systems to present our results on friday.

    I might be able to use some of this code in our system :-). I'll see how it goes.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. C# Packet loss/Ping program
    By Jordan in forum CSharp Tutorials
    Replies: 30
    Last Post: 09-02-2009, 01:42 PM
  2. Replies: 8
    Last Post: 06-05-2009, 02:40 AM
  3. Perl is Dead. Long live Perl.
    By Kernel in forum News
    Replies: 3
    Last Post: 08-10-2007, 10:49 AM
  4. (Script) Copy content to clipboard, how?
    By annannienann in forum Visual Basic Programming
    Replies: 0
    Last Post: 06-19-2007, 05:20 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts