Posts Tagged ‘domain’

get registered domain in Python and Javascript

April 5, 2011

reg-dom-libs are a set of libraries for C, PHP and Perl to convert an arbitrary domain name to the registered domain name.

  • for simple domains, like or, the task is trivial.
  • for more complicated ones, like or, handling the second level subdomain is a little painful.
  • for exoteric ones, like or or 公司.cn, the problem becomes virtually impossible.
  • after seeing stupid ones, like (believe it or not, the registered domain is!), I gave up finding an elegant algorithm for the problem.
  • a full list of valid registered domain is necessary. luckily, it is available (and nightly updated) here.

inspired by reg-dom-libs, I’ve ported the algorithm to Python and Javascript.
see the tests at the end of each file for an example of the usage.

a demo is availble here.