#!/usr/local/bin/perl # #################################################################### # SINGLE THREAD PERL PORT SCANNER # Modified from FORK PERL PORT SCANNER By Jonathan Worthington # This script is made available under the sames terms as Perl itself. # #################################################################### use strict; use warnings; use IO::Socket::INET; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; print "Port Scan for IRN $mon/$mday/$year $hour:$min:$sec \n"; my $iFile = $ARGV[0]; open(INPUT, '<', $iFile) or die $!; while () { my $hostIp = substr($_, 0, 14); my $hostName = substr($_, 18, 7); my $portStart = substr($_, 26, 5); my $portTimes = substr($_, 32, 5); #Auto-flush. $| = 1; #Port scan host. print "Scanning $hostName, $hostIp, Port $portStart for $portTimes number of Ports \n"; my $port; my $endPort = $portStart+$portTimes - 1; for ($port=$portStart; $port<=$endPort; $port++) { #Attempt to connect to $host on $port. my $socket; my $success = eval { #local $SIG{'ALRM'} = sub { die "Timed out" }; #alarm(1); $socket = IO::Socket::INET->new( PeerAddr => $hostIp, PeerPort => $port, Proto => 'tcp', Timeout => "1" ) }; #If the port was opened, say it was and close it. if ($success) { print "Host $hostName Port $port: Open\n"; shutdown($socket, 2); } else { print "Host $hostName Port $port: NOT Open\n"; } } } close INPUT; print " \n"; print "*************************************************** \n"; print "Port Scan for IRN is COMPLETE on this segment \n"; print "*************************************************** \n";