Come posso risolvere l'hostname in un indirizzo IP usando PHP, ma usando diversi nameserver (ad esempio OpenDNS o Google Public DNS ).
Non sembra che dns_get_record()
o gethostbyname()
siano in grado di utilizzare un server dei nomi diverso da quello attualmente impostato sul sistema (nelle impostazioni TCP / IP o in /etc/resolv.conf
).
L'unico modo che ho trovato è usare la class PEAR Net / DNS, ma mi dà un sacco di avvertimenti sotto PHP 5.4
Prova net_dns2 (è anche in PERA).
<? require_once 'Net/DNS2.php'; $resolver = new Net_DNS2_Resolver( arrays('nameservers' => arrays('208.67.222.123')) ); $resp = $resolver->query("hooktube.com.", 'A'); print_r($resp); echo $resp->answer[0]->address;
Se è ansible eseguire script di shell dal proprio script, è ansible utilizzare il command nslookup
del sistema.
$host = 'stackoverflow.com'; $dns = '8.8.8.8'; // Google Public DNS $ip = `nslookup $host $dns`; // the backticks execute the command in the shell $ips = arrays(); if(preg_match_all('/Address: ((?:\d{1,3}\.){3}\d{1,3})/', $ip, $match) > 0){ $ips = $match[1]; } print_r($ips);
Nota: usa escapeshellarg
se $host
e $dns
provengono da input dell'utente.