diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d9637b9 --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from setuptools import setup, find_packages +import sys, os + +__version__ = '0.1' + +setup(name='whois', + version=__version__, + description="", + long_description="", + classifiers=[], + keywords='whois', + author='Larry Kim', + author_email='admin@relip.org', + url='http://github.com/relip/python-whois', + license='MIT', + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + include_package_data=True, + zip_safe=False, + install_requires=[ + # -*- Extra requirements: -*- + ], + entry_points=""" + # -*- Entry points: -*- + """, +) diff --git a/src/parse.py b/src/parse.py new file mode 100644 index 0000000..e69de29 diff --git a/src/test.py b/src/test.py new file mode 100644 index 0000000..0f1c504 --- /dev/null +++ b/src/test.py @@ -0,0 +1,5 @@ +import os + +whoisServers = {} +execfile(os.path.join(os.path.dirname(os.path.realpath(__file__)), "whois-servers.conf"), {}, whoisServers) +print whoisServers diff --git a/src/whois-servers.conf b/src/whois-servers.conf new file mode 100644 index 0000000..933177d --- /dev/null +++ b/src/whois-servers.conf @@ -0,0 +1,4 @@ +whoisServer = { + "so": "whois.nic.so", + "id": "whois.pandi.or.id", +} diff --git a/src/whois-servers.conf.save b/src/whois-servers.conf.save new file mode 100644 index 0000000..014e1c8 --- /dev/null +++ b/src/whois-servers.conf.save @@ -0,0 +1,4 @@ +whois = { + "so": "whois.nic.so", + "id": "whois.pandi.or.id", +} diff --git a/src/whois.py b/src/whois.py new file mode 100644 index 0000000..20dd599 --- /dev/null +++ b/src/whois.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +import sys +import os +import socket + +class Whois(object): + def __init__(self, domain): + self.domain = domain + self.tld = self.domain.split(".")[-1] + + self.whoisServers = {} + f = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "whois-servers.conf"), "r") + exec("self.whoisServers = %s"%(f.read())) + + def chooseServer(self): + if self.whoisServers.has_key(self.tld): + return self.whoisServers[self.tld] + else: + return self.tld + ".whois-servers.net" + + def run(self, redirect=True): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + s.connect((self.whoisServer, 43)) + except: + print "ERROR Could not connect to whois server %s"%(self.whoisServer) + + s.send(self.domain + "\r\n") + + result = "" + + while True: + buffer = s.recv(512) + + if not buffer: break + + result += buffer + + return result +