#!/usr/bin/perl

$whois = "/usr/local/bin/whois";

open(LOG, ">./whois-records3.txt") or die "nope.";

for($i=97;$i<123;$i++) {
  for($j=97;$j<123;$j++) {
    for($k=97;$k<123;$k++) {
      $domain = chr($i) . chr($j) . chr($k);
      print STDERR "checking for $domain...\n";
      $com = $domain . ".com";
      get_whois($com);
      $org = $domain . ".org";
      get_whois($org);
      $net = $domain . ".net";
      get_whois($net);
    }
  }
}

sub get_whois {
  local($d) = $_[0];
  sleep 60; # avoid whois query limit timeout

  open(WHOIS, "$whois $d |") or die "nope.";
  @whois = <WHOIS>;
  if($whois[0] =~ /^No match for/) {
    print STDERR " $d is open.\n";
    print LOG "$d\n";
  } else {
    print STDERR " $d is registered.\n";
    print LOG "$d y\n";
  }
  close(WHOIS);
}
