zininho 0 Denunciar post Postado Março 3, 2011 Implementei a função gethostbyaddr($ip) em um script para salvar o nome de host das máquinas que acessam um site da rede interna. Só que a resolução dos IPs só está sendo feita em PCs com Linux. Nos PCs com Windows 7 ou XP, ele retorna o número de IP novamente. Ai está um exemplo da utilização <?php $ip = $_SERVER['REMOTE_ADDR']; //retorna o IP corretamente $host = gethostbyaddr($ip); //Nos PCs com Linux retorna o Nome de Host Corretamente. Nos com Windows retorna o IP. ?> Compartilhar este post Link para o post Compartilhar em outros sites
gremio10 14 Denunciar post Postado Março 3, 2011 gethostbyaddr Das contribuições dos Usuários desta página do gethostbyaddr do Php.net DNS lookup on Win + Linux: <?php /* * This function returns the real hostname of an ip address. * * @param: $ip - the ip address in format x.x.x.x where x are * numbers (0-255) or the hostname you want to lookup * @return: returns the hostname as string. Something like 'user-id.isp-dialin.tld' * * Warning: $ip must be validated before calling this function. */ function nslookup($ip) { // execute nslookup command exec('nslookup '.$ip, $op); // php is running on windows machine if (substr(php_uname(), 0, 7) == "Windows") { return substr($op[3], 6); } else { // on linux nslookup returns 2 diffrent line depending on // ip or hostname given for nslookup if (strpos($op[4], 'name = ') > 0) return substr($op[4], strpos($op[4], 'name =') + 7, -1); else return substr($op[4], strpos($op[4], 'Name:') + 6); } } // example function call to get hostname of user ip: echo nslookup($_SERVER['REMOTE_ADDR']); ?> rhj at rhj dot info 25-Nov-2009 08:27 DNS lookup with timeout on a Mac: <?php function dns_timeout($ip) { $res=`nslookup -timeout=2 -retry=1 $ip`; if (preg_match('/name = (.*).\n/', $res, $out)) { return $out[1]; } else { return $ip; } } ?> Compartilhar este post Link para o post Compartilhar em outros sites
Periscuelo 20 Denunciar post Postado Março 3, 2011 amigo rVenson fiz o teste em minha maquina onde uso o Windows 7 e a função funcionou normalmente. O Servidor está instalado no Windows. Talvez seja este o problema. Abraços. Compartilhar este post Link para o post Compartilhar em outros sites
zininho 0 Denunciar post Postado Março 4, 2011 O meu servidor aqui é linux. Eu já tinha testado essa outra função que foi postada no site do php.net e não deu resultado. Mas acredito que seja algum problema com a rede por aqui, já que nem o nmblookup e nslookup estão retornando o nome de host. Compartilhar este post Link para o post Compartilhar em outros sites
Periscuelo 20 Denunciar post Postado Março 4, 2011 Testou a função instalando um server no Windows e jogando o script la? As vezes pode ser o firewall ou o samba ou algo do genero. Abraços. Compartilhar este post Link para o post Compartilhar em outros sites
jcalebe 0 Denunciar post Postado Março 5, 2011 Veja se isso ajuda: http://calebe.co.cc/programacao/php-detector-de-ip-com-ip-reverso/ Só transfira o gethostbyaddr() para dentro do foreach, com as suas devidas alterações. :thumbsup: Abraços :grin: Compartilhar este post Link para o post Compartilhar em outros sites