Created
June 12, 2014 10:26
-
-
Save mzdakr/c83cbafd357299a88280 to your computer and use it in GitHub Desktop.
ホスト名のIPアドレスを解決するPHPです。CNAMEがきちんとAで解決されるまでループします。
This file contains 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
<?php | |
$hostname = $_GET['hostname']; | |
$res = get_ipaddr($hostname); | |
if($res){ | |
echo json_encode($res); | |
} else { | |
echo json_encode(array('error' => 'error')); | |
} | |
function get_ipaddr($hostname) | |
{ | |
$results = dns_get_record($hostname); | |
foreach ($results as $result) { | |
if($result['type'] == 'A'){ | |
return $result; | |
} | |
if($result['type'] == 'CNAME'){ | |
return get_ipaddr($result['target']); | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment