Created
November 22, 2017 13:23
-
-
Save ab5w/b480d113946f400336c6c6c80afe32bc to your computer and use it in GitHub Desktop.
ptr ns lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
//PTR nameserver lookup | |
if (!isset($argv[1])) { exit(); } | |
$ip = exec("dig " . $argv[1] . " A +short"); | |
$ip = explode('.', $ip); | |
$reverse_zone = $ip[2] . '.' . $ip[1] . '.' . $ip[0]; | |
$reverse_zone = $reverse_zone . ".in-addr.arpa"; | |
exec("dig in ns " . $reverse_zone . " | grep -E \"" . $reverse_zone . ".*NS\" | grep -v \; | awk '{print $5}'", $output); | |
if (empty($output)) { | |
echo "No reverse record set." . PHP_EOL; | |
} else { | |
echo "PTR ". $reverse_zone . PHP_EOL; | |
$output = implode(PHP_EOL, $output) . PHP_EOL; | |
echo "Nameservers:" . PHP_EOL . $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment