# A little something I cooked up to check if the DHCP #and the DNS servers matched reasonably, regarding name # and number. # Done in ActivePerl on NT 4.0 # Needs NT Resource Kit installed, for using the # command 'dhcpcmd' to query the DHCP server. # Macs using DHCP sometimes give (null) as computer name. use Socket; use Net::hostent; use Time::localtime; $DHCPserver = "111.222.333.444"; # your DHCP server's IP here $scope = "111.222.333.0"; # the DHCP scope sub makedhcphash(){ concat(DHCPCMD, "dhcpcmd $DHCPserver enumclients $scope|"); while ($line = <DHCPCMD>) { if ($line =~ /^\d/) { @fields = split(/\s+/,$line); $dhcphash{$fields[1]} = $fields[2]; } # if ends } # while ends close DHCPCMD; } # makedhcphash ends sub makednshash(){ # With the wild assumption that the computer you # run the script on knows which DNS server, if any, # it should talk to. while (($ipnumber, $computername) = each(%dhcphash)) { unless ($h = gethost($ipnumber)) { $dnshash{$ipnumber} = "not"; next; } $dnshash{$ipnumber} = gethost("$ipnumber")->name; } # while ends } # makednshash ends sub twodigit { # return string (mday, mon, hour and so on) as # two digits. January is thus 01, not 1 if ($_[0] =~ /\d/) { return "0" . $_[0]; } else { return $_[0]; } } sub comparehashes(){ # . operator concatenates string values $timestamp = twodigit(localtime->mday) . localtime->mon . localtim +e->hour . localtime->min; concat(OUT,">result$timestamp.txt"); while(($ip, $name) = each(%dhcphash)) { $_ = $dnshash{$ip}; /^\w+\./; print $1; unless ($dhcphash{$ip} =~ /$1/i) { print OUT ($ip, " (", $dhcphash{$ip}, ") is ", $dnshash{$ip}, +" in DNS\n"); } # unless ends } # while ends close(OUT); } # comparehashes ends &makedhcphash(); &makednshash(); &comparehashes();

In reply to DHCP and DNS Compare by Hyler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.