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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: