#!/s/std/bin/perl -w

use strict;
use CSL::DBs;
use CSL::Sybase;
use CSL::PlRPC_Krb5;
use DBI;
use Net::DNS;

my $dbhs = DBI->connect($CSL::DBs::sybase_proxy);

my $res   = Net::DNS::Resolver->new;
my @sigh;

open("FH", "</s/dhcp/common/conf/dummy.conf") or die("Could not open the specified file: $!");

my %exists;
while (<FH>) {
  if ($_ =~ /host\s+([\w\.-]+)\s+\{/) {
    my $host = $1;
    $host =~ s/\.cs\.wisc\.edu//;
    $host =~ s/\.stat\.wisc\.edu//;
    $exists{$host} = 1;
  }
}
close("FH");

open("FH", "</s/dhcp/common/conf/dhcpd.conf") or die("Could not open the specified file: $!");

while (<FH>) {
  if ($_ =~ /host\s+([\w\.-]+)\s+\{/) {
    my $host = $1;
    $host =~ s/\.cs\.wisc\.edu//;
    $host =~ s/\.stat\.wisc\.edu//;
    if (!$exists{$host}) {
      my $query = $res->search($host);
#      print "$host\n" if ($query);
      push(@sigh, $host) if ($query);
    }
  }
}
close("FH");

foreach (@sigh) {
  my $easy = $dbhs->selectall_arrayref("select cpuname from machines where cpuname like '$_'");

foreach (@$easy) {
  chomp(my $pants = $_->[0]);
  $pants =~ s/\s+//;
  print "$pants\n";
}
}

