Dnspy
A library for domain name manipulation
What
Dnspy offers functionality to manipulate fully qualified domain names (FQDNs), such as extracting subdomains and domain labels from a FQDN.
Installation
-
To install Dnspy, first download the compressed tar ball dnspy-3.0.tar.gz
-
Untar the downloaded file:
$ tar xvzf dnspy-3.0.tar.gz
-
Install the library
$ cd dnspy-3.0 $ python setup.py install
Usage
The following examples illustrate the use of this module:
# Using the Dnspy module to get sub-domains of a domain, given the default effective
# top-level domain (ETLD) list
>>> from dnspy.dnspy import Dnspy
>>> d = Dnspy() # Load the default ETLD list from Mozilla
>>> d.subdoms('a.b.c.d.google.com')
['com', 'google.com', 'd.google.com']
>>> d.subdoms('a.b.c.d.google.com', n = 4)
['com', 'google.com', 'd.google.com', 'c.d.google.com']
>>> d.subdoms('a.b.c.d.google.com', n = -1)
['com',
'google.com',
'd.google.com',
'c.d.google.com',
'b.c.d.google.com',
'a.b.c.d.google.com']
>>> d.domlabels('a.b.c.d.google.com')
['com', 'google', 'd']
>>> d.domlabels('a.b.c.d.google.com', n = 4)
['com', 'google', 'd', 'c']
To illustrate the use of a custom ETLD list:
$ cat /tmp/custom_etlds.txt
co.uk
testetld
Now use the custom ETLD list:
>>> from dnspy.dnspy import Dnspy
>>> d = Dnspy()
>>> d.subdoms('www.google.testetld')
['testetld', 'google.testetld', 'www.google.testetld']
The etld_url
parameter passed to the Dnspy constructor, can point to any
valid URL, including http URLs.
To run unit tests:
$ cd test/
$ python -m unittest test_dnspy
...
----------------------------------------------------------------------
Ran 3 tests in 2.813s
OK
NOTE: Running unit tests requires the library to be installed.
Uninstall
To uninstall, remove the package directory from the disk. On debian systems, for instance:
$ rm -rf /usr/local/lib/python2.7/dist-packages/dnspy
License
Copyright © 2019 Sandeep Yadav
Distributed under the Apache license