0: #!/usr/bin/perl
1: use warnings;
2: use Net::Ping;
3: use Socket;
4:
5: print "Enter the subnet you wish to scan just the first 3 octet's\n";
6: $ipnumber =<STDIN>;
7: chomp $ipnumber;
8: @iparray = map $ipnumber. ".$_",1..254 ;
9: #print @iparray;
10: #open (ERRORLOG, ">errorlog");
11: open (OFFLINE,">offline");
12: #open (ONLINE,">online");
13:
14: #my @iparray = qw( www.slashdot.org www.deja.com www.perlmonks.org );
15:
16:
17: my $proto = 'icmp';
18: my $def_timeout = '0';
19: my $bytes = '64';
20:
21: my $p = Net::Ping->new($proto, $def_timeout , $bytes);
22: $! = 1;
23: foreach my $host (@iparray) {
24: print ONLINE "$host online \n" if $p->ping($host);
25: print ERRORLOG "$host offline \n" unless $p->ping($host,1);
26: print OFFLINE "$host \n" unless $p->ping($host,1);
27: }
28: $p->close();
29: close OFFLINE;
30: close ERRORLOG;
31: close ONLINE;
32:
33: open (IPLIST, "offline");
34: #open (OFFLINEHOST, ">offlinehost");
35: @list=<IPLIST>;
36: $list = @list;
37: #print "@list\n";
38: chomp @list;
39: my $i;
40: my $peer_host;
41: format STDOUT_TOP =
42: IP# Machine name
43: ---------------- ------------------------------------ -------
44: .
45: format STDOUT =
46: @<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<
47: $i, $peer_host, "offline"
48: .
49: foreach $i (@list) {
50: $peer_host = gethostbyaddr(inet_aton($i), AF_INET);
51: #$peer_host = gethostbyaddr(inet_aton($i), AF_INET);
52: #print OFFLINEHOST "$peer_host and ipaddress $i\n";
53: #print OFFLINEHOST "$peer_host and ipaddress $i\n";
54: write
55: }
56: close OFFLINE; In reply to Pingger Script4 by muaddib2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |