Welcome to WebmasterWorld Guest from 23.22.17.192

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Host Name

gethostbyaddr

   
12:25 am on Sep 10, 2010 (gmt 0)



Hello

Dos Anyone have an idea how may i get only the Domain name of a host name to display without all the useless things from the front of it?



For Example the fallowing Host names
to be Replaced by the Example i will give bellow them

customer7806.pool1.unallocated-106-128.orangehomedsl.co.uk
cpe-24-161-61-235.hvc.res.rr.com
79-113-108-166.rdsnet.ro


orangehomedsl.co.uk
hvc.res.rr.com
rdsnet.ro

Edit:

maybe it needs some preg_replace or str_replace or whatever ...
5:39 am on Sep 10, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



This will remove the first part

$rest = gethostbyaddr();
list($subdomain, $rest) = explode('.', $rest, 2);

From your examples it is unclear what you consider 'useless', perhaps repeat until no 'useless' bits remain ?
7:02 pm on Sep 10, 2010 (gmt 0)



Hi Dave

i had found this script months ago when i started to play with the ISP Tracking etc...

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$host = preg_replace("/^[^.]+./", "*.", $fullhost);
?>


IP address <?=$ip?> | Host: <?=$host?>


It works Nice on the -79-113-108-166.rdsnet.ro- Host as it outputs : *.rdsnet.ro

But for Hosts like this long one

customer7806.pool1.unallocated-106-128.orangehomedsl.co.uk

it will output only
*.pool1.unallocated-106-128.orangehomedsl.co.uk

i Want it to only output whats before the .ro,.com,.net,.org

Like
rdsnet.ro



but it s confusing on domains with more tlds like .co.uk , .ro.com or whatever

and i have no idea what to output from your code....
5:04 am on Sep 11, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



i Want it to only output whats before the .ro,.com,.net,.org


in that case cpe-24-161-61-235.hvc.res.rr.com
becomes
rr.com ?

Without a list of all tlds I can not see how to do that ?

Perhaps looking for hyphen junk would suffice

$rest = gethostbyaddr();
while ( count( explode('-', $rest ) ) > 1 ) { // maybe >2 to allow single hyphen
list($subdomain, $rest) = explode('.', $rest, 2);
}
echo rest;

Not perfect for sure, and would fail on say my-example.com
11:35 am on Sep 11, 2010 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



For Example the fallowing Host names
to be Replaced by the Example i will give bellow them

customer7806.pool1.unallocated-106-128.orangehomedsl.co.uk
cpe-24-161-61-235.hvc.res.rr.com
79-113-108-166.rdsnet.ro

orangehomedsl.co.uk
hvc.res.rr.com
rdsnet.ro


This would seem to be incorrect.

in that case cpe-24-161-61-235.hvc.res.rr.com
becomes
rr.com ?


That looks to be more correct. "rr.com" appears to be the domain in this case.

As daveVk suggests, I think you would need to have a list of all the possible TLDs you are checking for in order to know how many periods to check for eg. ".com" (just 1 period), ".co.uk" (2 periods) and work backwards to find the domain?
1:47 pm on Sep 11, 2010 (gmt 0)



Here You can find a list of all tld including for example .co.uk or .com

[publicsuffix.org...]
6:11 pm on Sep 11, 2010 (gmt 0)



i Want it to only output whats before the .ro,.com,.net,.org



in that case cpe-24-161-61-235.hvc.res.rr.com
becomes
rr.com ?


Yes
Thats what i want



but there are Domains like
orangehomedsl.co.uk
That would output only co

Your Code is almost perfect for some Host names


@penders

yes thats what i wanted .. i forgot the others were just subdomains
but the rr.com domain was too small and didnt looked right on it

i dont have a list of two dotted domains with two tlds in :(

For now Dave's script is helpful
but if anyone knows something better please let me know :)

Thanks
3:55 pm on Sep 12, 2010 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



bhukkel: Here You can find a list of all tld including for example .co.uk or .com
[publicsuffix.org...]


That is an enormous list! Thanks. However, I'm a bit puzzled that the list itself appears to omit ".co.uk"? Yet, the front page of that site states that it is included? "pvt.k12.wy.us" is another possible suffix mentioned, but doesn't appear 'as is' in the list?

IMHO, due to the massive variety of possible public suffixes, I don't see how you can reliably extract the domain name (from your visitor IP logs?) without in some way referencing this list/DB? Apparently Chrome, Firefox and Opera make use of this list and "reg-dom libs - C, Perl and PHP free software libraries for adding PSL support to your application". It does sound a bit overkill I must admit.
5:02 pm on Sep 12, 2010 (gmt 0)



.co.uk is in the list, only as *.uk

The wildcard character * (asterisk) matches any valid sequence of characters in a hostname part. See [publicsuffix.org...]

I use this list in one of my projects to extract domain names. and it works great.
10:47 pm on Sep 12, 2010 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



The wildcard character * (asterisk) matches any valid sequence of characters in a hostname part.


Ah OK, thanks for the clarity. So in that sense you can validate that the domain is of the correct form and has the correct number of parts (top, second, third level etc.), but not necessarily whether the domain is strictly valid? eg. Using the list you can determine that "x1.x2.example.zzz.uk" is of the correct form since it matches "*.uk", so the domain is "example.zzz.uk". However, afaik "zzz" is not a valid SLD of the "uk" TLD - so this domain could not actually be registered?

Another exception which doesn't appear to be covered by the exceptions for .uk domains in the list is Nominet itself: "nic.uk"? Or have I missed it?
5:22 pm on Sep 13, 2010 (gmt 0)



The exceptions are normally covered by the exclamation mark. For example !bl.uk. But i see they missed nic.uk. Nothing is perfect :)

You are right about strictly valid with * character.