public function execute($hostname) { $server = $this->getContext(); $query = Utils::getHostForLookup($hostname, $server->getHostname(), true); $result = @$this->query($query); $response = new Response\NetDnsResponse(); $response->setHostname($hostname); $response->setServer($server); $response->setQuery($query); if ($result) { $response->listed(); $answer = ''; $resultTXT = @$this->query($query, 'TXT'); if ($resultTXT) { foreach ($resultTXT->answer as $txt) { $answer .= $txt->text[0]; } } else { $resultA = @$this->query($query, 'A'); if ($resultA && isset($resultA->answer[0])) { $answer = $resultA->answer[0]->address; } } $response->setAnswer($answer); } return $response; }
/** * @test */ public function getHostForLookUp() { $this->assertSame('1.0.0.127.example.com', Utils::getHostForLookup('127.0.0.1', 'example.com', true)); $this->assertSame('1.0.0.127.example.com', Utils::getHostForLookup('localhost', 'example.com', true)); $this->assertSame('localhost.example.com', Utils::getHostForLookup('localhost', 'example.com', false)); }