-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchk_interface.pl
More file actions
52 lines (37 loc) · 1.28 KB
/
chk_interface.pl
File metadata and controls
52 lines (37 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -w
#use strict;
use IO::Socket::PortState qw(check_ports);
$num_args = $#ARGV + 1;
if ($num_args != 2) {
print "\nUsage: chk_interface.pl interfacefilename outputfilename\n";
exit; }
my $interfaces = $ARGV[0];
my $outfile = $ARGV[1];
my $timeout = 2;
print $outfile;
open (OUTF, ">$outfile") or die "can't create logfile; $!";
open (INTERFACES_FILE, $interfaces) or die "Can't open '$interfaces' : $!";
print "Checking $interfaces ....\n";
print "=================================================";
print OUTF "Checking $interfaces ....\n";
print OUTF "=================================================";
while (<INTERFACES_FILE>) {
chomp;
($ip, $port,$text) = split(":");
my %port_hash = (
tcp => {
$port => {}
}
);
my $host_hr = check_ports($ip,$timeout,\%port_hash);
for my $port (sort {$a <=> $b} keys %{$host_hr->{tcp}}) {
my $yesno = $host_hr->{tcp}{$port}{open} ? ":Connected" : ":Notconnected";
$line = sprintf "\n%-20s %-12s %-14s %-s", "ip: $ip", "port: $port", "$yesno", "$text";
print $line;
print OUTF $line;
}
}
close INTERFACES_FILE;
print "\n===================Completed=====================\n";
print OUTF "\n===================Completed=====================\n";
close OUTF;