Jun
26

Tip: Using dig to Show Nameservers

If the need to scan a list of domains arises, be it one or one hundred, I have one handy Perl script that will list all nameservers of a domain. This script uses the command dig, and filters and lists the result. Do note that Perl must be installed to do this script.

# vi mx_checker.pl

#!/usr/bin/perl

$file=$ARGV[0];
chomp($file);

@list = `cat $file`;

foreach $domain(@list) {
chomp($domain);
$ns = `dig ns $domain +short`;
chomp($ns);
$ns =~s/\n/\t/g;
print “$domain\t$ns\n”;
}

To make the script executable, change the permissions:

# chmod 700 mx_checker.pl

Then build the list of domains by listing it on a text file, one domain per file.

# vi domains.txt

google.com
yahoo.com
usautoparts.com

Now that the script and domain list is ready, it is time to execute the script:

# ./mx_checker.pl domains.txt

The nameservers will then be listed and can be piped to a text file, which can be exported to a spreadsheet as tab-separated values.

# ./mx_checker.pl domains.txt >> nameservers.xls

Related Posts

1 Comment to “Tip: Using dig to Show Nameservers”

  • mica February 23, 2011 at 3:25 am

    i’m receiving compilation errors:

    Backslash found where operator expected at ./mx_checker.pl line 13, near “$domain\”
    (Missing operator before \?)
    Backslash found where operator expected at ./mx_checker.pl line 13, near “$ns\”
    (Missing operator before \?)
    syntax error at ./mx_checker.pl line 13, near “$domain\”
    Execution of ./mx_checker.pl aborted due to compilation errors.

Post comment

CommentLuv Enabled

Powered by 1and1.comGlobat Webhosting Earn with Your BlogAdvertise @ PinoyTux

Search PinoyTux

Subscribe to Email Feeds

Enter Email Address:

Blog Lounge

Popular Posts

Recent Posts

Drop your Card Here

Recent Comments

Site Stats