Last active
December 15, 2015 07:18
-
-
Save waffle2k/5222045 to your computer and use it in GitHub Desktop.
Example of using Net::PortTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use Net::PortTest; | |
on 143 => sub { | |
my $sock = shift; | |
my $results = {}; | |
my $rc = -1; | |
$results->{banner} = $sock->getline; | |
$rc = 0 | |
if $results->{banner} =~ '^\* OK'; | |
return $rc, $results; | |
}; | |
on 25 => sub { | |
my $sock = shift; | |
my $results = {}; | |
my $banner = $sock->getline; | |
if( $banner =~ /^(\d{3})/ ){ | |
$results->{banner} = $1; | |
if( $results->{banner} >= 200 and $results->{banner} < 300 ){ | |
return 0,$results; | |
} | |
} else { | |
return -2, $results; | |
} | |
return -1,$results; | |
}; | |
# Alias a non standard port to an existing check | |
alias qw/ 1025 2025 / => 25; | |
my $results = run_tests '216.40.42.129' => 143; | |
# Run again, but against the non standard ports | |
$results = run_tests '10.0.0.1' => qw/ 25 1025 2025 /; | |
use Data::Dumper; | |
print Dumper( $results ),"\n"; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment