Results 1 to 5 of 5

Thread: The Ping Command

  1. #1
    Join Date
    Nov 2007
    Beans
    53
    Distro
    Ubuntu 9.10 Karmic Koala

    Question The Ping Command

    I am pinging google and sending the output to a text file via the command:

    Code:
    ping google.com >> ping
    But I want to only want to view connections that have a time greater than 400ms how would I do that.

    I tried piping it trough grep with a number like so:

    Code:
    ping google.com |grep #
    But that didn't work so after a google search I figured that I would start a new thread.

    Thank you for the help and sorry if I posted this in the wrong section.
    Attached Images Attached Images
    --

    "I never think of the future - It comes soon enough"
    - Albert Einstein

  2. #2
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: The Ping Command

    You can do a bash script for that!

  3. #3
    Join Date
    Nov 2007
    Beans
    53
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: The Ping Command

    Quote Originally Posted by n0dix View Post
    You can do a bash script for that!
    I am not really well versed in programing in bash is there a place that you would suggest that I start (e.g. a site that talks about some things that I would need to know to start writing a script that will coincide with what I need.
    --

    "I never think of the future - It comes soon enough"
    - Albert Einstein

  4. #4
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: The Ping Command

    Here is a perl script tha should work (I have nothing over 400ms away)

    Save it, mark it executable, and run it like

    sudo ping.pl www.google.com

    if you want to add a count to it, I can teach you how to do that.


    Code:
     use Net::Ping;
     $host = $ARGV[0];
     
        # High precision syntax (requires Time::HiRes)
     $p = Net::Ping->new("icmp");
     $p->hires();
     ($ret, $duration, $ip) = $p->ping($host, 5.5);
     if (1000 * $duration >= 400){
    	 printf("$host [ip: $ip] is alive (packet return time: %.2f ms)\n", 1000 * $duration)
     }else{
    	 #do nothing else
     }
     #printf("$host [ip: $ip] is alive (packet return time: %.2f ms)\n", 1000 * $duration)
     if $ret;
     $p->close();
    It's way possible with bash, and awk, Im just not that good today, and perl makes it easier.

  5. #5
    Join Date
    Jun 2009
    Beans
    329
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: The Ping Command

    well, i have developed something. i think its bash scripting, but I'm not sure.

    here it is:
    Code:
    ping google.com -c 1 -i 0.25 -w 4.0 >a
    echo "6 a">b
    wc -l a >c
    diff b c || diff b c >RESULTS.txt
    ./ping
    it is also in the attached document (should be executable)
    if RESULTS.txt ever shows up, the ping took longer than 4 seconds.
    Attached Files Attached Files
    always learning more every day.
    this is the best tech community i have ever known.

Tags for this Thread

Bookmarks

Posting Permissions

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