Lost Password?


  #1 (permalink)  
Old 04-26-2007, 10:40 AM
Jordan's Avatar   
Jordan Jordan is online now
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,572
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default 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";
#       }
}
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-29-2007, 01:29 PM
icepack's Avatar   
icepack icepack is offline
Programmer
 
Join Date: Jul 2006
Location: North Carolina
Posts: 115
Rep Power: 9
icepack is on a distinguished road
Send a message via AIM to icepack
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Packet loss/Ping program Jordan CSharp Tutorials 14 11-28-2008 05:18 PM
JavaScript:Tutorial, Using an External Script TcM Javascript 7 09-11-2007 08:39 AM
Perl is Dead. Long live Perl. Kernel Programming News 3 08-10-2007 11:49 AM
(Script) Copy content to clipboard, how? annannienann Visual Basic Programming 0 06-19-2007 06:20 PM


All times are GMT -5. The time now is 03:14 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads