Skip to content

Commit

Permalink
Automatically convert IPs to ARPA domain
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Feb 5, 2017
1 parent 45ab9b5 commit 2b7e3f0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/DefaultResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ private function doResolve($name, array $types, $options) {

assert(array_reduce($types, function ($result, $val) { return $result && \is_int($val); }, true), 'The $types passed to DNS functions must all be integers (from \Amp\Dns\Record class)');

if (($packedIp = @inet_pton($name)) !== false) {
if (isset($packedIp[4])) { // IPv6
$name = wordwrap(strrev(bin2hex($packedIp)), 1, ".", true) . ".ip6.arpa";
} else { // IPv4
$name = inet_ntop(strrev($packedIp)) . ".in-addr.arpa";
}
}

$name = \strtolower($name);
$result = [];

Expand Down

0 comments on commit 2b7e3f0

Please sign in to comment.