Extract domain name from a host name

后端 未结 3 783
逝去的感伤
逝去的感伤 2021-02-05 10:34

Is there a programatic way to find the domain name from a given hostname?

given -> www.yahoo.co.jp return -> yahoo.co.jp

The approach that works but is very slo

3条回答
  •  北海茫月
    2021-02-05 11:09

    Your algorithm is the right one. Since zone cuts are not reflected in the domain name (you see domain cuts - the dots - but not zone cuts), it is the only correct one.

    An approximate algorithm is to use a list of zones, like the one mentioned by Alnitak. Remember that these static lists are not authoritative, they lack many registries, they are stale, etc.

提交回复
热议问题