This tool can extract TLD (Top Level Domain), domain extensions (Second Level Domain + TLD), domain name, and hostname from fully qualified domain names. Written in Ruby for Unix. Recognizes all countries, top level domains and second level domains.
You can download it from the following link: https://packetstormsecurity.com/files/download/83340/basedomainname-0.1.tar.gz
Source: https://packetstormsecurity.com/files/83340/Top-Level-Domain-Extractor-0.1.html

