Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 39 guests online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Programmingarrow Help with Perl
EH-Net
May 21, 2013, 10:13:31 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Help with Perl  (Read 2787 times)
0 Members and 1 Guest are viewing this topic.
zenlakin
Newbie
*
Offline Offline

Posts: 13


View Profile
« on: October 15, 2012, 02:02:51 PM »

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 Edit: October 15, 2012, 02:04:52 PM by zenlakin » Logged
hayabusa
Hero Member
*****
Offline Offline

Posts: 1632



View Profile
« Reply #1 on: October 15, 2012, 02:42:56 PM »

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 Edit: October 15, 2012, 02:46:38 PM by hayabusa » Logged

~ 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
Newbie
*
Offline Offline

Posts: 13


View Profile
« Reply #2 on: October 15, 2012, 02:52:35 PM »

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!!
Logged
hayabusa
Hero Member
*****
Offline Offline

Posts: 1632



View Profile
« Reply #3 on: October 15, 2012, 02:55:08 PM »

Any time!  If you end up working it into something really cool, be sure to share, so others can learn from it, too!
« Last Edit: October 15, 2012, 02:59:05 PM by hayabusa » Logged

~ 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
Newbie
*
Offline Offline

Posts: 13


View Profile
« Reply #4 on: October 15, 2012, 03:08:01 PM »

Will do!!
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.066 seconds with 23 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.