Do you know when a new server or network device is added to your network? Does someone else let you know a week later that a new device needs to be monitored? Are you putting a list of IP's together in a text file and writing a for loop to ping each of these servers? How about an IP iterator that walks from a start IP to end end IP.
#!/usr/bin/perl -w
use strict;
use Net::Ping;
use IO::Socket;
sub ip_fr_dotted { unpack 'N', pack 'C4', split /\./, $_[0] }
sub ip_to_dotted { join '.', unpack 'C4', pack 'N', $_[0] }
my $start = ip_fr_dotted($ARGV[0]);
my $end = ip_fr_dotted($ARGV[1]);
for (my $ip=$start; $ip<=$end; $ip++) {
print("\n ", ip_to_dotted($ip));
&ping_ip($ip);
}
sub ping_ip{
my $p = Net::Ping->new("icmp",2);
if( $p->ping($_[0]) ){
print " available ";
&id_device($_[0]);
}
$p->close();
}
sub id_device {
my $host = shift || ip_to_dotted($_[0]);
#windows
if( &port_check('tcp',$host,'139') == 0 && &port_check('udp',$host,'13
+8') == 0 && &port_check('udp',$host,'137') == 0 ){
print "windows";
}
}
sub port_check{
my $handle = IO::Socket::INET->new (Proto=>$_[0], PeerAddr=>$_
+[1], PeerPort=>$_[2] );
if($handle){
return 0;
}else{
return 1;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.