Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^4: Ping sweep with reporting

by StarkRavingCalm (Sexton)
on May 17, 2007 at 20:19 UTC ( #616105=note: print w/replies, xml ) Need Help??

in reply to Re^3: Ping sweep with reporting
in thread Ping sweep with reporting

Ok, here's what I have:
#!/usr/bin/perl use strict; use warnings; my $ping = "/bin/ping"; while (<DATA>) { chomp; my $ping_out = `$ping $_ 2> /dev/null`; chomp ($ping_out); if ($ping_out !~ /bytes from/) { print "$_ isn't pinging\n"; } else { print "$_ is up\n"; } } __DATA__ myserver02

And here's the output:
root@stewie ~# perl isn't pinging


Replies are listed 'Best First'.
Re^5: Ping sweep with reporting
by liverpole (Monsignor) on May 17, 2007 at 22:13 UTC
    Great ... now you're getting somewhere!

    The next step is to debug your results.

    First of all, what happens when you do the ping by hand?  To be on the safe side, you can formulate the whole command before executing it, so you can cut-and-paste:

    my $cmd = "$ping $_ 2> /dev/null"; print "Debug: command is '$cmd'\n"; my $ping_out = `$cmd`;

    So when you run that, you should get something like:

    Debug: command is '/bin/ping myserver02 2> /dev/null'

    What happens when you run that command (/bin/ping myserver02 2> /dev/null) at a shell prompt?  Does running ping directly produce the output you expect?

    If so, then try printing the output in the program, and compare it visually:

    my $ping_out = `$cmd`; chomp ($ping_out); print "Debug: ping results => '$ping_out'\n";

    Does it print the results you expect?  (ie. the results you get doing it by hand?)

    If there's a problem, you should now, most likely, know where it is.  Perhaps the remote server is down.  Or perhaps the output from ping isn't quite in a format that you expect.

    What happens when you follow these steps?  Are you able to find the bug and fix it?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://616105]
[Corion]: Hi Discipulus!
[marto]: hopefully you guys are also well :)
[Corion]: marto: Yeah - I'm looking for a week off in a week, even if it'll be a trip to Amsterdam ;)
[Discipulus]: oh thanks, i'm always at well as the ratchet or bucket
[Corion]: But I'm slowly starting to get into programming again - yesterday I translated my talk for YAPC::E (in Amsterdam) to English, and decided to put my Jekyll-clone to rest for the time being
[Corion]: Discipulus++ # being well is like being earnest
[marto]: hopefully next year I'll be in a position to go to Perly things in Europe :)
[Corion]: Maybe I'll use the Real Jekyll a bit to get a feel for how it actually works, and to get annoyed by it ;)
[Corion]: marto: That would be cool :) There is no kids care at Perly events unfortunately, so it's not entirely family friendly
[Corion]: I think I should define a set of (say) five projects through which I rotate from time to time, just to prevent myself from being bored/annoyed by the problems they get stuck in ;)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-07-27 07:39 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (404 votes). Check out past polls.