/** * @return array */ private function readRecord() { // First the pesky domain names - maybe not so pesky though I suppose $domain = $this->readDomainLabel(); $ans_header_bin = $this->readResponse(10); // 10 byte header $ans_header = unpack('ntype/nclass/Nttl/nlength', $ans_header_bin); $this->debug('Record Type ' . $ans_header['type'] . ' Class ' . $ans_header['class'] . ' TTL ' . $ans_header['ttl'] . ' Length ' . $ans_header['length']); $typeid = $this->types->getById($ans_header['type']); $extras = array(); $data = ''; $string = ''; switch ($typeid) { case 'A': $ipbin = $this->readResponse(4); $ip = inet_ntop($ipbin); $data = $ip; $extras['ipbin'] = $ipbin; $string = $domain . ' has IPv4 address ' . $ip; break; case 'AAAA': $ipbin = $this->readResponse(16); $ip = inet_ntop($ipbin); $data = $ip; $extras['ipbin'] = $ipbin; $string = $domain . ' has IPv6 address ' . $ip; break; case 'CNAME': $data = $this->readDomainLabel(); $string = $domain . ' alias of ' . $data; break; case 'DNAME': $data = $this->readDomainLabel(); $string = $domain . ' alias of ' . $data; break; case 'DNSKEY': case 'KEY': $stuff = $this->readResponse(4); // key type test 21/02/2014 DC $test = unpack('nflags/cprotocol/calgo', $stuff); $extras['flags'] = $test['flags']; $extras['protocol'] = $test['protocol']; $extras['algorithm'] = $test['algo']; $data = base64_encode($this->readResponse($ans_header['length'] - 4)); $string = $domain . ' KEY ' . $data; break; case "NSEC": $data = $this->ReadDomainLabel(); $string = $domain . " points to " . $data; break; case 'MX': $prefs = $this->readResponse(2); $prefs = unpack('nlevel', $prefs); $extras['level'] = $prefs['level']; $data = $this->readDomainLabel(); $string = $domain . ' mailserver ' . $data . ' (pri=' . $extras['level'] . ')'; break; case 'NS': $nameserver = $this->readDomainLabel(); $data = $nameserver; $string = $domain . ' nameserver ' . $nameserver; break; case 'PTR': $data = $this->readDomainLabel(); $string = $domain . ' points to ' . $data; break; case 'SOA': // Label First $data = $this->readDomainLabel(); $responsible = $this->readDomainLabel(); $buffer = $this->readResponse(20); $extras = unpack('Nserial/Nrefresh/Nretry/Nexpiry/Nminttl', $buffer); // butfix to NNNNN from nnNNN for 1.01 $dot = strpos($responsible, '.'); if ($dot !== false) { $responsible[$dot] = '@'; } $extras['responsible'] = $responsible; $string = $domain . ' SOA ' . $data . ' Serial ' . $extras['serial']; break; case 'SRV': $prefs = $this->readResponse(6); $prefs = unpack('npriority/nweight/nport', $prefs); $extras['priority'] = $prefs['priority']; $extras['weight'] = $prefs['weight']; $extras['port'] = $prefs['port']; $data = $this->readDomainLabel(); $string = $domain . ' SRV ' . $data . ':' . $extras['port'] . ' (pri=' . $extras['priority'] . ', weight=' . $extras['weight'] . ')'; break; case 'TXT': case 'SPF': $data = ''; for ($string_count = 0; strlen($data) + (1 + $string_count) < $ans_header['length']; $string_count++) { $string_length = ord($this->readResponse(1)); $data .= $this->readResponse($string_length); } $string = $domain . ' TEXT "' . $data . '" (in ' . $string_count . ' strings)'; break; case "NAPTR": $buffer = $this->ReadResponse(4); $extras = unpack("norder/npreference", $buffer); $addonitial = $this->ReadDomainLabel(); $data = $this->ReadDomainLabel(); $extras['service'] = $addonitial; $string = $domain . " NAPTR " . $data; break; } return array('header' => $ans_header, 'typeid' => $typeid, 'data' => $data, 'domain' => $domain, 'string' => $string, 'extras' => $extras); }