.

Help with Perl

<<

zenlakin

User avatar

Newbie
Newbie

Posts: 13

Joined: Thu May 19, 2011 6:45 am

Post Mon Oct 15, 2012 2:02 pm

Help with Perl

Hello all. I am trying to mess with Perl a bit and am trying to put together a ping script but for some reason I am not getting the desired result. I just want to come up with a simple scrip that will ping a range of IP addresses and tell me if they are active or not. Below is what I have come up with so far but to no avail.

"#!/usr/bin/perl

use Net::Ping;

$p = Net::Ping->new("icmp");
$host = "192.168.xx.xx";
@range = (1 .. 255);
foreach $host (@range)
{
print "$host is dead.\n"
unless $p->ping($host);
}
$p->close();
"
Last edited by zenlakin on Mon Oct 15, 2012 2:04 pm, edited 1 time in total.
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1662

Joined: Mon Jan 29, 2007 2:59 pm

Post Mon Oct 15, 2012 2:42 pm

Re: Help with Perl

A little bit modified (single class C), but try working from this:

  Code:
#!/usr/bin/perl

 use Net::Ping;
    $my_addr='192.168.26.100';
    $p = Net::Ping->new("icmp");
    $p->bind($my_addr); # Specify source interface of pings
    @host_array=(1 .. 255);
    foreach $host (@host_array)
    {
        $ip="192.168.26.$host";
        print "$ip is ";
        print "NOT " unless $p->ping($ip, 2);
        print "reachable.\n";
        sleep(1);
    }
    $p->close();


The bind interface helped, as well as a need to clearly define the host you were after.

Hope that helps.

(Edit-
You can get a better feel for the Net::Ping from the docs:
http://perldoc.perl.org/Net/Ping.html )
Last edited by hayabusa on Mon Oct 15, 2012 2:46 pm, edited 1 time in total.
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
<<

zenlakin

User avatar

Newbie
Newbie

Posts: 13

Joined: Thu May 19, 2011 6:45 am

Post Mon Oct 15, 2012 2:52 pm

Re: Help with Perl

Ahh I see now. Initially when I was playing with the bind syntax I was using double quotes instead os single quotes which explains why it wouldn't run. I will modify my other script that I had using bind and try it again. Thanks!!
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1662

Joined: Mon Jan 29, 2007 2:59 pm

Post Mon Oct 15, 2012 2:55 pm

Re: Help with Perl

Any time!  If you end up working it into something really cool, be sure to share, so others can learn from it, too!
Last edited by hayabusa on Mon Oct 15, 2012 2:59 pm, edited 1 time in total.
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
<<

zenlakin

User avatar

Newbie
Newbie

Posts: 13

Joined: Thu May 19, 2011 6:45 am

Post Mon Oct 15, 2012 3:08 pm

Re: Help with Perl

Will do!!

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron
.
Powered by phpBB® Forum Software © phpBB Group.
Designed by ST Software