Hi all,
I am trying to resolve IP addresses into their hostnames using gethostbyaddr().
The weird thing is that I get different results if I run php from a shell than if I access the script through the web server.
More specifically, the following lines in an executable file:
#!/usr/local/bin/php
<?
print( gethostbyaddr( "198.182.196.56" ) );
?>
... will print out "www.linux.org". If I stick the <?...?> block into a .php file and access it through my browser, I get "198.182.196.56".
I'm pretty lost here.... any suggestions appreciated.
I'm running Apache 1.3.29, mod_php 4.3.4 statically linked, FreeBSD 5.2
thanks
antoine
gethostbyaddr() returns only numerical IPs :(
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
See if this works instead:
Code: Select all
$ip = '198.182.196.56';
$host = `host $ip`;
echo $host;Joe -- yes, I guess something is not set up right, since the CLI version of php returns the hostname OK while the apache module returns the numerical IP.
kettle_drum -- thanks for the suggestion, but I was hoping to be able to use native php functions. Otherwise you add the overhead of starting a shell to run the 'host' command every time a request gets served.
Also, on my system 'host' returns:
user@search:~#host 198.182.196.56
56.196.182.198.IN-ADDR.ARPA domain name pointer http://www.linux.org
So I'd have the extra overhead of doing a regexp to extract the actual hostname from that string. I've read the man page and there are no switches that allow you to just return the hostname without all the crap at the start of the line.
What really bugs me is that gethostbyaddr() works _fine_ from within a shell script, but behaves differently within apache.
kettle_drum -- thanks for the suggestion, but I was hoping to be able to use native php functions. Otherwise you add the overhead of starting a shell to run the 'host' command every time a request gets served.
Also, on my system 'host' returns:
user@search:~#host 198.182.196.56
56.196.182.198.IN-ADDR.ARPA domain name pointer http://www.linux.org
So I'd have the extra overhead of doing a regexp to extract the actual hostname from that string. I've read the man page and there are no switches that allow you to just return the hostname without all the crap at the start of the line.
What really bugs me is that gethostbyaddr() works _fine_ from within a shell script, but behaves differently within apache.