How Do I Display the ISP Hostname of the Visitor?

Hello everybody!

I have this website. and on one page I setup this php script that shows the IP address of the visitor along with the browser that the visitor is using.

Now there is another thing that I want to show to the visitor and that is the hostname if their ISP.

Say the IP address of a visitor is: 123.456.78.90
and their hostname is something like:

I want to display that information to the visitor, so it would show on the page.
I’m not a php guru, but so far I managed to use any script that I found on the internet. However I wasn’t able to find one that shows the hostname, all of them are about the IP address.

I wonder if you guys can help me with it, I also looked up on the forums but didn’t find the answer to my question…


You might want to look at [fphp]gethostbyaddr [/fphp]

Hi Swdev! Thank you for reply!

I already tried that… it returns the IP address…

However, here is the piece of php code that I’m using:

$hst = $_SERVER[“HTTP_HOST”]; // This shows the domain name where the website is.
$uri = $_SERVER[“REQUEST_URI”]; // This line shows the name of the requested page.
$rmt = $_SERVER[“REMOTE_ADDR”]; // This shows visitor’s IP address.
$br = $_SERVER[“HTTP_USER_AGENT”]; // This shows the browser version the visitor is using.

echo “<font color=‘#A00000’>Your IP address is:</font><br/><font color=‘#FF0000’> $rmt
<font color=‘#A00000’>The browser you are using is:</font><br/> $br<br/>”;

try this one out:

$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);

ok i found this

// For Linux...

function gethost ($ip) {
 $host = `host $ip`;
 return (($host ? end ( explode (' ', $host)) : $ip));

// For Win32...

function nslookup ($ip) {
 $host = split('Name:',`nslookup $ip`);
 return ( trim (isset($host[1]) ? str_replace ("\
".'Address:  '.$ip, '', $host[1]) : $ip));

it will do what you want BUT remember its executing command as shell/command prompt on *NIX/Windows. so you should have SAFE MODE off (i think)
ok here’s where i found it.

it gets the output from these command then you can use regular expression to get what you want

hope this helps

Wow guys!
I’m impressed by the speed that you reply to my thread… almost can’t keep up.
Hi Computerages… same thing, that returns the IP
Hello Jas! for some reason your solution doesn’t work for me. I’m using WinXP for the server, and I tried the Win version of your code. It doesn’t return anything, not even an error.

ok, first check your safe mode is off,
second just try to run


and see if it does anything. this would give a heads up. if it does then you can make your own function. RIGHT??

I guess the IP in question couldnt be resolved, which is probably the case as you are trying it locally.

Hi Drzoid!
ok my setup… i have couple of computers on the network.
One of them is the webserver, another is this computer that I’m using, and I’m trying to access my website from the internet, using the domain name and not the internal ip address of the webserver, that is on the network.

I think I’m not quite getting what you’re trying to tell me… my bad.
I don’t know what you mean by “check your safe mode is off”
About writting my own function… consider me a noob, that might be something simple, but I guess I don’t know how to do it.

By the way… this is the page that I’m trying to setup:

Sorry, I am confused :slight_smile: … where are you running the non-working gethostbyaddr()?

The computer that I am using now to reply to you guys, is just one on the network.
The webserver computer is in another room, and I never use that for anything else, it is exclusively used as a webserver.

ok try this code and see what the output is

	echo 'safe mode on';
	echo system('nslookup');	

EDIT: correction of code

You probably cant resolve it, because there is no DNS server which holds its record, right?

Wow… it says “safe mode on”

Server: UnKnown Address:

That’s what it says…

then if you want you can turn off the safe mode (NOT A GOOD IDEA THOUGH IF YOU DONT TAKE PROPER CARE).
you can turn it off in php.ini (if in your control)

that’s ok(i think because you are on network). now try to put an ip address that you know has something like you want and test that ip

Then it cant work,

But it will most definitely work outside.

I don’t know what you mean by that… :frowning:

You mean it will actually work for somebody that is not on the network?? that would be what I want.