コード例 #1
0
ファイル: Dns.php プロジェクト: talesoft/tale-framework
 public static function lookUp($hostName, $type = RecordType::ANY, $withAuthEntries = false, $withAdditionalLookups = false)
 {
     $authNs = null;
     $additionalLookups = null;
     $result = null;
     if ($withAdditionalLookups) {
         $result = @dns_get_record($hostName, $type, $authNs, $additionalLookups);
     } else {
         if ($withAuthEntries) {
             $result = @dns_get_record($hostName, $type, $authNs);
         } else {
             $result = @dns_get_record($hostName, $type);
         }
     }
     if (!$result) {
         throw new Exception("Failed to get DNS records for {$hostName}, maybe there is no DNS available");
     }
     foreach ($result as $record) {
         $type = RecordType::getValue($record['type']);
         switch ($type) {
             case RecordType::A6:
                 (yield new A6($record['host'], $record['chain'], Address::fromString($record['ipv6']), $record['masklen'], $record['ttl']));
                 break;
             case RecordType::AAAA:
                 (yield new Aaaa($record['host'], Address::fromString($record['ipv6']), $record['ttl']));
                 break;
             case RecordType::A:
                 (yield new A($record['host'], Address::fromString($record['ip']), $record['ttl']));
                 break;
             case RecordType::CNAME:
                 (yield new Cname($record['host'], $record['target'], $record['ttl']));
                 break;
             case RecordType::HINFO:
                 (yield new Hinfo($record['host'], $record['cpu'], $record['os'], $record['ttl']));
                 break;
             case RecordType::MX:
                 (yield new Mx($record['host'], $record['target'], $record['pri'], $record['ttl']));
                 break;
             case RecordType::NS:
                 (yield new Ns($record['host'], $record['target'], $record['ttl']));
                 break;
             case RecordType::PTR:
                 (yield new Ptr($record['host'], $record['target'], $record['ttl']));
                 break;
                 //TODO: SRV record isn't fetched
             //TODO: SRV record isn't fetched
             case RecordType::SOA:
                 (yield new Soa($record['host'], $record['mname'], $record['rname'], $record['serial'], $record['refresh'], $record['retry'], $record['expire'], $record['minimum-ttl'], $record['ttl']));
                 break;
             case RecordType::TXT:
                 (yield new Txt($record['host'], $record['txt'], $record['ttl']));
                 break;
             default:
                 (yield new Record($record['host'], $type, $record['ttl']));
                 break;
         }
     }
 }
コード例 #2
0
ファイル: Dns.php プロジェクト: Talesoft/tale-net
 public static function hasRecordType($hostName, $type = RecordType::ANY)
 {
     return checkdnsrr($hostName, RecordType::getName($type));
 }