CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Ping script

 



Doueven
New User

Jan 26, 2015, 7:41 AM

Post #1 of 1 (2689 views)
Ping script Can't Post

I'm a placement student and I've been given the task to write a perl script to scan a given IP block, ping each IP within the block, return true if the IP is reachable and output all data to a csv file.

I'm going to be building on this script over the next few weeks to eventually compile all network information into a csv file (thinking of it like a network database). I've started a bit but I'm no guru and I'm only self taught so I'm having trouble figuring out where to go from here and how to get there.

I want to be able to run the script and give it a IP range or CIDR block and the script to ping every IP in the range or block and output to a csv file the IP that was pinged and if it was reached.


Code
perl map.pl 130.15.241/24


Here is the code I have so far.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use Net::Netmask;

my $block = new Net::Netmask ($ARGV[0]);

print "Block:\t\t".$block."\n";
print "Base:\t\t".$block->base()."\n";
print "Netmask:\t".$block->mask()."\n";
print "Hostmask:\t".$block->hostmask()."\n";
print "CIDR:\t\t".$block->bits()."\n";
print "Size:\t\t".$block->size()."\n";
print "Max Block:\t".$block->maxblock()."\n";
print "Broadcast:\t".$block->broadcast()."\n";

open (CSVFILE, ">", "csvfile.out") || die "Cannot open file 'csvfile.out' $!";

close (CSVFILE) || die;

system("pause");


I know I can give it a range or CIDR block and it will return the basic information. I'm guessing I'll need the Net::Ping or something similar to do the pinging but I don't understand how.

Any help would be greatly appreciated.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives