#!/usr/bin/perl -wT # ckdns.perl # confirm dynamic DNS update # ToDo: # reverse lookup (just for kicks) # CGI form for non-default lookup use Net::DNS; use Time::localtime; use strict; use vars qw( $default $name $time $pid @ppp $pppip @mx $line $nameserver @ARGV $nameresolution $res $query $rr $queryNS $resNS $resMX ); my $default = 'myddnshost.dom'; my $ns1 = 'dns.some.dom'; my $ns2 = 'dns.someother.dom'; my $ns3 = 'dns.yetanother.dom'; my $ns4 = 'dns.andanother.dom'; # using nameservers' address instead of name # might be a bit better, but hostname # provides more informative output. select ((select(STDOUT), $|=1) [0]); # hot STDOUT fixes sequence problem - TPJ #11 $ENV { 'PATH' } = ''; # unTaint backticks by clearing path ## REPORT HEADER ## my $tm = localtime; printf "\n%02d-%02d-%04d ", $tm->mon+1, $tm->mday, $tm->year+1900; printf "%02d:%02d:%02d\n", $tm->hour, $tm->min, $tm->sec; print "$^X $] ", "\Net::DNS ", Net::DNS->version, "\n"; ## PPP0 ADDRESS ## my $pid = `/bin/cat /var/run/ppp0.pid` or die "ppp0 down, abort"; # abort script if ppp0 down @ppp = `/sbin/ifconfig ppp0`; foreach $line (@ppp) { if($line =~ /inet addr/) { $line =~ s/\s+inet addr:(\S+)\s+.*/$1/; $pppip = $line; } } print "\n\nlocal ppp0\n"; print "================\n"; print "$pppip\n"; # print "$name : ", "$pppip\n"; ## FORWARD LOOKUPS ## @ARGV = ("$default" ) unless @ARGV; my $name = "@ARGV"; print "\n$name forward lookup\n"; print "=============================\n"; my @nameservers=( $ns1, $ns2, $ns3, $ns4 ); my $nameserver; foreach $nameserver(@nameservers) { print "Nameserver : $nameserver\n"; my $res = new Net::DNS::Resolver; $res->nameservers($nameserver); my $query = $res->search("$name"); if ($query) { my $rr; foreach $rr ($query->answer) { next unless $rr->type eq "A"; print "$name : ", $rr->address, "\n\n"; } } else { print "query failed: ", $res->errorstring, "\n\n"; } } ## AUTHORITATIVE NAMESERVERS ## print "\n$name authoritative nameservers\n"; print "========================================\n"; my $resNS = new Net::DNS::Resolver; my $queryNS = $resNS->query("$name", "NS"); if ($queryNS) { foreach $rr ($queryNS->answer) { next unless $rr->type eq "NS"; printf "%s\n", $rr->nsdname; } } else { print "\Nameserver query failed: ", $resNS->errorstring, "\n"; } ## MX RECORDS ## print "\n\n$name MX records\n"; print "==============================\n"; my $resMX = new Net::DNS::Resolver; @mx = mx($resMX, $name); if (@mx) { foreach $rr (@mx) { print $resMX->answerfrom," says : ", $rr->preference, " ", $rr +->exchange, "\n"; } } else { print "MX record query failed: ", $resMX->errorstring, "\n"; } # END

In reply to (code) ixnay to nslookupay (first Catacombs submission, ugly nasty bad code) by ybiC

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.