Something i found the other day in a post, improved it a little.
Here you go:
Code
#!/usr/bin/perl
use IO::Socket;
if ($#ARGV < 1) {
usage();
exit;
}
sub usage {
print "usage: $0 <port> <timeout>\n\n";
}
# define port here
my $port = $ARGV[0];
my $time = $ARGV[1];
main();
sub ipgen(){
my $range1 = 223; # dont want experimental/multicast
my $range2 = 254;
$oct1 = int(rand($range1)) + 1;
$oct2 = int(rand($range2)) + 1;
$oct3 = int(rand($range2)) + 1;
$oct4 = int(rand($range2)) + 1;
#get rid of loopbacks and private ips
if($oct1 == 127 || $oct1 == 172 || $oct1 == 192 || $oct1 == 10){
$ip = &ipgen(); #local or private then get new adress
}else{
$ip = "$oct1.$oct2.$oct3.$oct4"; # address to return
}
return $ip; #return to calle
}
sub main {
$gr = "\033[1;31m";
$bl = "\033[0;36m";
$nu = "\033[0m";
while(1==1){
$target = &ipgen(); # get random ip to scan
print "[$bl*$nu] Scanning $target \n"; # output
my $sock = new IO::Socket::INET ( # try to create socket to chose random address
PeerAddr => $target,
PeerPort => $port, # change this number to change ports you want to detect
Proto => 'tcp',
Timeout => $time, # you can get away with a timeout of 1 second but i have 2 to be safe
);
if($sock){ # if socket opened (port open)
print "[$gr+$nu] Found $target \n"; # print to screen
open(DAT, ">>result.txt") || die("Cannot Open Output File"); # open results file
print DAT "$target $port\n"; # append findings to end of file
close(DAT); # close the file
}
close($sock); # close the socket
}
}
Generates valid ip addresses, opens a socket, tells you if it connected, then saves the address to a file.
save that code
Code
$ ./scanner.pl 5900 2
would randomly find vnc's running on a box with a 2 second timeout.
All random, but depending on the service, you can find alot.