+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, Script to check various ping results in Coding and Web Development; Whenever our internet connection fails, I have to run through a series of checks, namely: 1. Check I can ping ...
  1. #1

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,529
    Thank Post
    527
    Thanked 2,648 Times in 2,049 Posts
    Blog Entries
    24
    Rep Power
    925

    Script to check various ping results

    Whenever our internet connection fails, I have to run through a series of checks, namely:

    1. Check I can ping the edge router in school
    2. Check I can ping the headend router at RM
    3. Check I can ping the DNS server/Exchange Server etc... at our LEA
    4. Check I can ping the RM proxy

    Depending on the results of the above, I will then connect through to the switch on which the edge router connects and run various pings from that.

    Eventually, I narrow it down to

    a) Bust switch
    b) Bust edge router
    c) External issue

    Now, are there any perl gurus out there who could code up a script that checks pings and their results? Also, is it possible to script a telnet or ssh session, and running a command on that session, looking at the result it returns?

    Cheers in advance...

  2. #2

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,867
    Thank Post
    412
    Thanked 778 Times in 651 Posts
    Rep Power
    182
    Quote Originally Posted by localzuk View Post
    Whenever our internet connection fails, I have to run through a series of checks, namely:

    1. Check I can ping the edge router in school
    2. Check I can ping the headend router at RM
    3. Check I can ping the DNS server/Exchange Server etc... at our LEA
    4. Check I can ping the RM proxy
    I got the LA to tell me what path traffic took to various key things (our hosted boxes, for example) and watched them with Nagios.

  3. #3

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,529
    Thank Post
    527
    Thanked 2,648 Times in 2,049 Posts
    Blog Entries
    24
    Rep Power
    925
    Quote Originally Posted by powdarrmonkey View Post
    I got the LA to tell me what path traffic took to various key things (our hosted boxes, for example) and watched them with Nagios.
    Yeah, I do the same, but when Nagios isn't as thorough as a sequential analysis of where the problem lies. For example, recently I could ping our edge router from the nagios server, but not from the switch it was connected to... A quick reset of the switch later and it was fine. But nagios couldn't have shown that, whereas my newly created 'checklist' does. And if I can perlify it, it means I can run it as a nagios check anyway...

  4. #4

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,867
    Thank Post
    412
    Thanked 778 Times in 651 Posts
    Rep Power
    182
    Well no, it's never going to be a replacement for going and having a proper look, but at least I could glance at it and see that intermediate stuff was working and so probably wasn't able to fix it.

    Edit: oh, I should read your post more carefully. I monitored key switchgear along the way, so that I had a path to the edge not just the edge router.
    Last edited by powdarrmonkey; 7th January 2009 at 05:38 PM.

  5. #5


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,706
    Thank Post
    354
    Thanked 807 Times in 722 Posts
    Rep Power
    348
    Straight answer is yes, it can be done including the SSH question with the caveat that there needs to be an ability to load an sshkey onto the "host" you wish to ssh into to perform commands as I'd be a bit wary of throwing the password in cleartext at it.

    I could write that in bash now, but I'm on the track with perl hopefully this week and next to see whether I could do that also.

    Sounds useful

  6. #6

    Join Date
    Mar 2008
    Location
    Bromley
    Posts
    287
    Thank Post
    15
    Thanked 21 Times in 21 Posts
    Rep Power
    17
    If this can be done please share the code would find it useful

  7. #7

    Join Date
    Mar 2009
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    biterscripting PING script

    localzuk:

    I am NOT a scripting guru, but was able to put together for you a ping script quickly. (I am not a networking/systems guru either - just know a little bit of scripting.)

    Here is the script. Feel free to use it, edit it, make it better, etc. It is in biterscripting - you can use any language. (I like biterscripting because you can write a script in no time at all.)

    Code:
    # PING SCRIPT
    # Following are passed as input arguments. They are ip addresses.
    var str edge, headend, server
    
    # Ping edge first. We will look for the lost packets in the response.
    var str reply
    var int lost
    system ping ("\""+$edge+"\"") > $reply
    # Parse the reply to get number of lost packets. That number is between "Lost = " and " ".
    stex "^Lost = ^]" $reply > null
    stex "[^ ^" $reply > null
    set $lost = makeint(str($reply))
    
    if ($lost > 0)
      echo "EDGE ROUTER DOWN"
    else
      # Edge router is OK.
      # Check the headend router the same way.
      .
      .
      .
      if ($lost > 0)
        echo "HEADEND ROUTER DOWN"
      else
        # Headend router is ok.
        # Check the server the same way.
        .
        .
        .
        if ($lost > 0)
          echo "SERVER DOWN"
        else
          .
          .
          .
          etc.
        endif # Check for server
      endif # Check for headend router
    endif # Check for edge router
    To run the script, save it in file ping.txt. Then call it using following command.

    Code:
    script ping.txt edge("1.2.3.4") headend("5.6.7.8") server("9.0.1.2")
    Very simple, really. You can also use URLs instead of IP addresses, such as "http://www.somesite.com". If you don't have biterscripting - it is free - download and install it from http://www.biterscripting.com. You can also follow their installation directions. (For your purposes, I don't think you need to do anything other than just install, then call the ping script as above.)

    Randi



SHARE:
+ Post New Thread

Similar Threads

  1. Script to check if app is running ...
    By pooley in forum Windows
    Replies: 4
    Last Post: 5th January 2009, 12:31 PM
  2. Double check this script please
    By FN-GM in forum Scripts
    Replies: 1
    Last Post: 28th May 2008, 11:41 PM
  3. script to ping IP adresses of Access Points
    By projector1 in forum Scripts
    Replies: 12
    Last Post: 16th May 2008, 08:47 PM
  4. No Ping Script
    By mattx in forum Scripts
    Replies: 16
    Last Post: 22nd February 2008, 09:03 PM
  5. Ping an IP address and log results
    By mrforgetful in forum Wireless Networks
    Replies: 13
    Last Post: 8th July 2006, 11:03 AM

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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