use warnings;

#Nagios Return Codes
$ng_ok = 0;
$ng_warn = 1;
$ng_crit = 2;
$ng_err = 3;

#Hostname
$myhostname = `hostname`;
chomp $myhostname;

#IP Address
@addressinfo = `ipconfig`;
foreach (@addressinfo){
   if (/IPv4 Address/){
      $address = "$_";
      chomp $address;
      (undef, $myaddress) = split(' : ', $address);
      last;
   }
}

#DNS Reverse Lookup
@dnsinfo = `nslookup $myaddress`;
foreach (@dnsinfo){
   if (/^Name:/){
      $name = "$_";
      chomp $name;
      (undef, $dnsname) = split(': +', $name);
   }
}

#Report Results
if ($dnsname !~ /$myhostname/i){
   print "CRITICAL: $myhostname does not match $dnsname";
   exit $ng_crit;
}

if ($dnsname && $myhostname){
   print "OK: $myhostname($myaddress) resolves to $dnsname";
   exit $ng_ok;
}


#catchall
print "Unknown Problem: $myhostname $myaddress $dnsname";
exit $ng_err;
