#!/usr/bin/perl use IO::Socket; ($addr, $min, $max) = @ARGV; $taddr = inet_aton($addr); $output = "OpenPorts.txt"; $time = localtime time; open (LIST, ">>$output"); print "Scanning $addr starting from port $min and ending at port $max.\n"; print LIST "Scanning $addr, starting from port $min and ending at port $max.\n"; print "Scan commencing at $time.\n"; print LIST "Scan commencing at $time.\n"; print "Port\t\tStatus\n"; print LIST "Port\t\tStatus\n"; for($i = $min; $i <= $max; $i++){ $sock = IO::Socket::INET->new(PeerAddr => "$taddr", PeerPort => "$i", Proto => 'tcp'); if ($sock){ print "$i\t\tOpen\n"; print LIST "$i\t\tOpen\n"; close $sock; } } $endtime = localtime time; print "Scan finished at $endtime."; print LIST "Scan finished at $endtime.\n\n"; close(LIST);