Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Bash script to ping by subnet
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Bash script to ping by subnet

I had need for simple up/down status in an easily mechanized format . . . and I haven't used xargs in a while, so I wrote this little gem (the beauty is in the eye of the beholder).

I thought someone else might find it useful.

https://gist.github.com/microlinux/74fc92f85738bffcdd5a

Thanked by 1obakfahad

Comments

  • rm_rm_ IPv6 Advocate, Veteran
    # [user@server ~]$ sping.sh 70.120.121.0/29
    # 70.120.121.1 down
    # 70.120.121.2 up
    # 70.120.121.3 up
    # 70.120.121.4 up
    # 70.120.121.5 up
    # 70.120.121.6 up

    Just use:

    $ nmap -sP 70.120.121.0/29
    
    Starting Nmap 6.00 ( http://nmap.org ) at 2015-02-12 13:13 YEKT
    Nmap scan report for mta-70-120-121-3.stx.rr.com (70.120.121.3)
    Host is up (0.33s latency).
    Nmap scan report for mta-70-120-121-4.stx.rr.com (70.120.121.4)
    Host is up (0.24s latency).
    Nmap scan report for mta-70-120-121-6.stx.rr.com (70.120.121.6)
    Host is up (0.24s latency).
    Nmap scan report for mta-70-120-121-7.stx.rr.com (70.120.121.7)
    Host is up (0.24s latency).
    Nmap done: 8 IP addresses (4 hosts up) scanned in 2.68 seconds
  • That's not as easily mechanized, fun or the same. I had a very specific need, but yeah, there are many ways to skin the cat.

  • rm_rm_ IPv6 Advocate, Veteran

    Microlinux said: That's not as easily mechanized

    There is also a "grepable" format suitable for use in other scripts (with 'grep' as the name says).

    $ nmap -oG - -sP 70.120.121.0/29
    # Nmap 6.00 scan initiated Thu Feb 12 13:16:06 2015 as: nmap -oG - -sP 70.120.121.0/29
    Host: 70.120.121.3 (mta-70-120-121-3.stx.rr.com)    Status: Up
    Host: 70.120.121.4 (mta-70-120-121-4.stx.rr.com)    Status: Up
    Host: 70.120.121.6 (mta-70-120-121-6.stx.rr.com)    Status: Up
    Host: 70.120.121.7 (mta-70-120-121-7.stx.rr.com)    Status: Up
    # Nmap done at Thu Feb 12 13:16:09 2015 -- 8 IP addresses (4 hosts up) scanned in 3.04 seconds
  • Why not use fping?

    fping -g 127.0.0.0/8

    Thanked by 1rm_
  • bsdguybsdguy Member
    edited February 2015

    That guy wrote a script and shares it for free. That should be good enough, no?

    Yes, sure there are other ways. So what? Should we stop once we have anything doing a given job? No! The whole open source world we all profit from is based on (among other factors) having options and variety and people trying new ways to do things.

    Professionally speaking I like his script for three simple reasons: It's liteweight, a sh(ell) is always and everywhere available, and everyone can easily look at it and understand it (which is far less true for, say, nmap).

  • FrankZFrankZ Veteran
    edited February 2015

    @bsdguy - It's fight club and these are some of the big boys, so no worries, they can take it. Besides, I've learned more stuff from these guys (and others) battling it out over the last couple of years then anywhere else. So I prefer they have at it. :)

  • @William said:
    Why not use fping?

    Primarily, because I can't.

    I would write an exhaustive list of reasons I did not use each and every existing potential solution, but I simply don't have time.

  • A very interesting way to generate a list of IPs given CIDR notation :)

  • outimeoutime Member
    edited February 2015

    @bsdguy said:
    That guy wrote a script and shares it for free. That should be good enough, no?

    Yes, sure there are other ways. So what? Should we stop once we have anything doing a given job? No! The whole open source world we all profit from is based on (among other factors) having options and variety and people trying new ways to do things.

    Do you think it is a good idea to create bash scripts for such simple functionalities which are easily invoked through software that is most likely installed in your system? We are not talking about passing 15 flags to nmap/fping/whatever but one or two. Plus I don't see the problem on giving feedback about this.

  • MicrolinuxMicrolinux Member
    edited February 2015

    outime said: Do you think it is a good idea to create bash scripts for such simple functionalities which are easily invokated through software that is most likely installed in your system?

    I will try not be ambiguous so as to prevent further wasted typing.

    1.) The tools at my disposal are existing software packages. Your installed software list doesn't match mine. I promise it doesn't. Swear to god.

    2.) I cannot install new software packages.

    3.) The reason I cannot install other software packages is policy. This policy is not up for debate, no how badly you would like to argue it. You could give me a million dollars to change it ... I wouldn't be able to. It's not an option. At all.

    4.) I need output in this specific format.

    5.) Any format other than this specific format, is not acceptable. No matter how badly you want it to be, it's not. Seriously, it's not. I mean it's really not.

    6.) I need it to be fast, I have more hardware resources than flexibility at my disposal. I know how badly you want to tell me that's not your situation, or how dumb that is. None of that changes my situation.

    7.) Please re-read 1 to 6 at least two more times. Really digest it. Take notes, have an argument with yourself in your head, that's right - get it all out.

    outime said: Plus I don't see the problem on giving feedback about this.

    Relevant feedback is: "hey, I have a better bash function for xyz" or "hey, I found a bug!".

    Relevant feedback is not "WHY DON'T DON'T YOU USE XYZ TOOL, BECAUSE LORD ALMIGHTY IT'S WHAT I WOULD DO".

    I posted this script here because I figured maybe someone else could find it useful, or perhaps modify it to be useful to them. I find the hoopla amusing, but I hope this explanation saves key strokes.

  • @outime

    That's not the point. The point is a) variety/options is good, b) sh scripts are a tool of the trade for admin jobs, c) Hey, someone is sharing his script. Take it or it leave it, as you please. But don't hit on it.

    Sidenote: I like nmap. A lot. But it's way heavier than a sh script. Besides, it's not everywhere installed.
    I personally wouldn't use his script myself. But I can respect his work, his idea, his reasoning and, most of all, his sharing his stuff.

Sign In or Register to comment.