Forum Moderators: DixonJones

Message Too Old, No Replies

How to get the HostName?

How does stats providers do it?

         

fischermx

10:43 pm on May 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do I need one of those ip databases? or there's something I can query to get it?

Creactiv

7:51 am on May 24, 2006 (gmt 0)

10+ Year Member



if you are using PHP you can use the gethostbyaddr function.

echo gethostbyaddr(IPaddress);

fischermx

3:12 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. I'm in Asp.Net though.

I found this for C#:

IPHostEntry IpEntry = Dns.GetHostByAddress(ip);
return IpEntry.HostName.ToString();

fischermx

3:24 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Definitely that works, but I'd like to know a little more.
What's behind of this function? Who are what is being queried?

Receptional Andy

3:29 pm on May 24, 2006 (gmt 0)



I believe you would just be querying the default DNS server configured on the web server you call the script from.

fischermx

4:43 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm testing the function on my development pc and works fine, using plain C# console application.
I wonder if this is the kind of call that would need an special permission from my hosting provider, or it is somehow unharmfull.

larryn

5:25 pm on May 24, 2006 (gmt 0)

10+ Year Member



fisher,

Typical analytics applications do a look up from the IP in the log file. Looking up IP's when serving pages is generally discouraged, as it can take many seconds for a reverse DNS probe, and then they are often unsuccessful.

Larry

fischermx

6:22 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Exactly, I've just noticed that. It takes a couple of seconds to resolve each.
However, there are services like those from statcounter or ad free stats that immediatly show up the hostname, so definitely they're resolving the names on the fly. I'm not going to resolve hostname on page serving, but instead I'm sort of doing a track service like those.
How do they do it?