Extract ISP name from hostname I want to get the high-level domain name (not sub-domain) from the hostname.
The idea is to &quot;guess&quot; the ISP name from the user's hostname. Ideas?

// no ISP when it's an IP
115.20.106.216 =&gt; null

// in these cases the domain name should be the ISP name
108-81-122-61.lightspeed.frokca.sbcglobal.net =&gt; sbcglobal.net
61-22-86-252.static.trlk.ca.charter.com =&gt; charter.com
c-28-8-222-102.hsd1.ca.comcast.net =&gt; comcast.net
CPE-128-122-18-181.hdbq1.win.bigpond.net.au =&gt; bigpond.net.au
dhcp-108-168-82-106.cable.user.start.ca =&gt; start.ca
ip68-100-26-186.dc.dc.cox.net =&gt; cox.net
ip-108-85-1-22.web.vodafone.de =&gt; vodafone.de
pool-68-86-186-222.washdc.fios.verizon.net =&gt; verizon.net
s51865a4f.adsl.online.nl =&gt; online.nl

// in these cases it's not very obvious
c-208-168-15-86.wifi.ties.k12.mn.us =&gt; k12.mn.us ?
cpe-66-181-81-222.tx.res.rr.com =&gt; res.rr.com ?

Note: All IP addresses are random.
Something like bigpond.net.au is 3-level. The main domain is sometimes 2-level and sometimes 3-level.
I found this tool which is doing exactly what I asked for
https://github.com/rvflash/publicsuffix-sql
It uses publicsuffix.org which maintains a list of public suffixes such as .com, .co.uk and pvt.k12.ma.us.
Using the function provided by the tool, we can simply do something like this:
select DOMAIN('115.20.106.216'); -- null 
select DOMAIN('cpe-45-37-121-56.nc.res.rr.com'); -- rr.com 
select DOMAIN('CPE00fc8d22x-CM023d22f4f0.cpe.net.cable.rogers.com'); -- rogers.com 
select DOMAIN('c-208-168-15-86.wifi.ties.k12.mn.us'); -- k12.mn.us 
select DOMAIN('CPE-128-122-18-181.hdbq1.win.bigpond.net.au'); -- bigpond.net.au