#!/usr/bin/perl -w #This could really stand to be improved, but it works for basic purposes #right now of identifying open ports on the given host. #The big improvement would be a hash containing basic jibberish to #send to given ports (eg 22, 21, 25, 80, 110) to see if they're #running standard services. use IO::Socket; use Getopt::Std; use strict; my %args; my $socket; my $host = "127.0.0.1"; my $lowport = 0; my $highport = 65535; my $wait = 10; my $outfile; my $jibberish = "\n"; my $usage = <$args{f}") or die "Couldn't open output file $args{f}"; } foreach ( $lowport ... $highport ) { my $response = ""; if ( $args{v} ) { $response .= "trying $host port $_\n"; } $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $_, Proto => "tcp", Type => SOCK_STREAM, Timeout => $wait) or next; $response .= "Got socket on $host port $_\n"; if ( $socket && $args{v} ) { # got a connection, let's throw some jibberish at it and # see what happens! print $socket $jibberish; my $response .= <$socket>; close($socket); } if ( $outfile ) { print $outfile $response; } else { print $response; } } if ( $outfile ) { close($outfile); }