Beispiel #1
0
 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;
         }
     }
 }
Beispiel #2
0
 public static function fromString($string)
 {
     $parts = StringUtil::mapReverse($string, ':', ['port', 'ip']);
     return new static(Address::fromString(trim($parts['ip'], '[]')), $parts['port']);
 }
Beispiel #3
0
 public function getEndPoint()
 {
     if (!$this->_domain) {
         throw new Exception("Failed to get endpoint on {$this}: No domain specified. Use the host-name, ipv4 or [ipv6]");
     }
     return new Ip\EndPoint(Ip\Address::fromDomain($this->_domain), $this->getRequiredPort());
 }
Beispiel #4
0
 public function testReverseLookUpV6()
 {
     $addr = Address::fromString('2a01:488:42:1000:50ed:8487:35:d5cd');
     $this->assertEquals('d.c.5.d.5.3.0.0.7.8.4.8.d.e.0.5.0.0.0.1.2.4.0.0.8.8.4.0.1.0.a.2.ip6.arpa', $addr->getReverseHostName());
     $this->assertEquals('talesoft.io', $addr->lookUpHostName());
 }
Beispiel #5
0
 public static function lookUpReverseFirst(Address $ipAddress)
 {
     return self::lookUpFirst($ipAddress->getReverseHostName(), RecordType::PTR);
 }