pax_global_header00006660000000000000000000000064127716000450014514gustar00rootroot0000000000000052 comment=735a6769fbafa17459bbc4b9eecab05e8261339f python-cymruwhois-1.6/000077500000000000000000000000001277160004500151125ustar00rootroot00000000000000python-cymruwhois-1.6/.gitignore000066400000000000000000000002511277160004500171000ustar00rootroot00000000000000*.py[co] # Packages *.egg *.egg-info dist build eggs parts bin develop-eggs .installed.cfg # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox python-cymruwhois-1.6/LICENSE.txt000066400000000000000000000021261277160004500167360ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2009-2016 Justin Azoff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. python-cymruwhois-1.6/README.rst000066400000000000000000000005761277160004500166110ustar00rootroot00000000000000Perform lookups by ip address and return ASN, Country Code, and Netblock Owner:: >>> import socket >>> ip = socket.gethostbyname("www.google.com") >>> from cymruwhois import Client >>> c=Client() >>> r=c.lookup(ip) >>> print r.asn 15169 >>> print r.owner GOOGLE - Google Inc. See http://packages.python.org/cymruwhois/ for full documentation. python-cymruwhois-1.6/cymruwhois.py000066400000000000000000000217361277160004500177060ustar00rootroot00000000000000#!/usr/bin/env python # cymruwhois.py # Copyright (C) 2009 Justin Azoff JAzoff@uamail.albany.edu # # This module is released under the MIT License: # http://www.opensource.org/licenses/mit-license.php import socket import errno try : import memcache HAVE_MEMCACHE = True except ImportError: HAVE_MEMCACHE = False def iterwindow(l, slice=50): """Generate sublists from an iterator >>> list(iterwindow(iter(range(10)),11)) [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] >>> list(iterwindow(iter(range(10)),9)) [[0, 1, 2, 3, 4, 5, 6, 7, 8], [9]] >>> list(iterwindow(iter(range(10)),5)) [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]] >>> list(iterwindow(iter(range(10)),3)) [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] >>> list(iterwindow(iter(range(10)),1)) [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]] """ assert(slice > 0) a=[] for x in l: if len(a) >= slice : yield a a=[] a.append(x) if a: yield a class record: def __init__(self, asn, ip, prefix, cc, owner): def fix(x): x = x.strip() try: x = str(x.decode('ascii','ignore')) except AttributeError: pass # for Python 3 return x self.asn = fix(asn) self.ip = fix(ip) self.prefix = fix(prefix) self.cc = fix(cc) self.owner = fix(owner) self.key = self.ip def __str__(self): return "%-10s %-16s %-16s %s '%s'" % (self.asn, self.ip, self.prefix, self.cc, self.owner) def __repr__(self): return "<%s instance: %s|%s|%s|%s|%s>" % (self.__class__, self.asn, self.ip, self.prefix, self.cc, self.owner) class asrecord: def __init__(self, asn, cc, owner): def fix(x): x = x.strip() if x == "NA": return None try: x = str(x.decode('ascii','ignore')) except AttributeError: pass # for Python 3 return x self.asn = fix(asn) self.cc = fix(cc) self.owner = fix(owner) self.key = "AS" + self.asn def __str__(self): return "%-10s %s '%s'" % (self.asn, self.cc, self.owner) def __repr__(self): return "<%s instance: %s|%s|%s>" % (self.__class__, self.asn, self.cc, self.owner) class Client: """Python interface to whois.cymru.com **Usage** >>> import socket >>> ip = socket.gethostbyname("www.google.com") >>> from cymruwhois import Client >>> c=Client() >>> r=c.lookup(ip) >>> print(r.asn) 15169 >>> print(r.owner) GOOGLE - Google Inc., US >>> >>> for r in c.lookupmany([ip, "8.8.8.8"]): ... print(r.owner) GOOGLE - Google Inc., US GOOGLE - Google Inc., US """ def make_key(self, arg): if arg.startswith("AS"): return "cymruwhois:as:" + arg else: return "cymruwhois:ip:" + arg def __init__(self, host="whois.cymru.com", port=43, memcache_host='localhost:11211'): self.host=host self.port=port self._connected=False self.c = None if HAVE_MEMCACHE and memcache_host: self.c = memcache.Client([memcache_host]) def _connect(self): self.socket=socket.socket() self.socket.settimeout(5.0) self.socket.connect((self.host,self.port)) self.socket.settimeout(10.0) self.file = self.socket.makefile("rw") def _sendline(self, line): self.file.write(line + "\r\n") self.file.flush() def _readline(self): return self.file.readline() def _disconnect(self): self.file.close() self.socket.close() def read_and_discard(self): self.socket.setblocking(0) try : try : self.file.read(1024) except socket.error as e: #10035 is WSAEWOULDBLOCK for windows systems on older python versions if e.args[0] not in (errno.EAGAIN, errno.EWOULDBLOCK, 10035): raise finally: self.socket.setblocking(1) def _begin(self): """Explicitly connect and send BEGIN to start the lookup process""" self._connect() self._sendline("BEGIN") self._readline() #discard the message "Bulk mode; one IP per line. [2005-08-02 18:54:55 GMT]" self._sendline("PREFIX\nASNUMBER\nCOUNTRYCODE\nNOTRUNC") self._connected=True def disconnect(self): """Explicitly send END to stop the lookup process and disconnect""" if not self._connected: return self._sendline("END") self._disconnect() self._connected=False def get_cached(self, ips): if not self.c: return {} keys = [self.make_key(ip) for ip in ips] vals = self.c.get_multi(keys) #convert cymruwhois:ip:1.2.3.4 into just 1.2.3.4 return dict((k.split(":")[-1], v) for k,v in list(vals.items())) def cache(self, r): if not self.c: return self.c.set(self.make_key(r.key), r, 60*60*6) def lookup(self, ip): """Look up a single address. .. warning:: Do not call this function inside of a loop, the performance will be terrible. Instead, call lookupmany or lookupmany_dict """ return list(self.lookupmany([ip]))[0] def lookupmany(self, ips): """Look up many ip addresses""" ips = [str(ip).strip() for ip in ips] for batch in iterwindow(ips, 100): cached = self.get_cached(batch) not_cached = [ip for ip in batch if not cached.get(ip)] #print "cached:%d not_cached:%d" % (len(cached), len(not_cached)) if not_cached: for rec in self._lookupmany_raw(not_cached): cached[rec.key] = rec for ip in batch: if ip in cached: yield cached[ip] def lookupmany_dict(self, ips): """Look up many ip addresses, returning a dictionary of ip -> record""" ips = set(ips) return dict((r.key, r) for r in self.lookupmany(ips)) def _lookupmany_raw(self, ips): """Do a look up for some ips""" if not self._connected: self._begin() ips = set(ips) for ip in ips: self._sendline(ip) need = len(ips) last = None while need: result=self._readline() if 'Error: no ASN or IP match on line' in result: need -=1 continue parts=result.split("|") if len(parts)==5: r=record(*parts) else: r=asrecord(*parts) #check for multiple records being returned for a single IP #in this case, just skip any extra records if last and r.key == last.key: continue self.cache(r) yield r last = r need -=1 #skip any trailing records that might have been caused by multiple records for the last ip self.read_and_discard() #backwards compatibility lookerupper = Client def lookup_stdin(): from optparse import OptionParser import fileinput parser = OptionParser(usage = "usage: %prog [options] [files]") parser.add_option("-d", "--delim", dest="delim", action="store", default=None, help="delimiter to use instead of justified") parser.add_option("-f", "--fields", dest="fields", action="append", help="comma separated fields to include (asn,ip,prefix,cc,owner)") if HAVE_MEMCACHE: parser.add_option("-c", "--cache", dest="cache", action="store", default="localhost:11211", help="memcache server (default localhost)") parser.add_option("-n", "--no-cache", dest="cache", action="store_false", help="don't use memcached") else: memcache_host = None (options, args) = parser.parse_args() #fix the fields: convert ['a,b','c'] into ['a','b','c'] if needed fields = [] if options.fields: for f in options.fields: fields.extend(f.split(",")) else: fields = 'asn ip prefix cc owner'.split() #generate the format string fieldwidths = { 'asn': 8, 'ip': 15, 'prefix': 18, 'cc': 2, 'owner': 0, } if options.delim: format = options.delim.join("%%(%s)s" % f for f in fields) else: format = ' '.join("%%(%s)-%ds" % (f, fieldwidths[f]) for f in fields) #setup the memcache option if HAVE_MEMCACHE: memcache_host = options.cache if memcache_host and ':' not in memcache_host: memcache_host += ":11211" c=Client(memcache_host=memcache_host) ips = [] for line in fileinput.input(args): ip=line.strip() ips.append(ip) for r in c.lookupmany(ips): print(format % r.__dict__) if __name__ == "__main__": lookup_stdin() python-cymruwhois-1.6/docs/000077500000000000000000000000001277160004500160425ustar00rootroot00000000000000python-cymruwhois-1.6/docs/Makefile000066400000000000000000000056711277160004500175130ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf _build/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html @echo @echo "Build finished. The HTML pages are in _build/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) _build/dirhtml @echo @echo "Build finished. The HTML pages are in _build/dirhtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) _build/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) _build/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) _build/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in _build/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) _build/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in _build/qthelp, like this:" @echo "# qcollectiongenerator _build/qthelp/cymruwhois.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile _build/qthelp/cymruwhois.qhc" latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex @echo @echo "Build finished; the LaTeX files are in _build/latex." @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ "run these through (pdf)latex." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) _build/changes @echo @echo "The overview file is in _build/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) _build/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in _build/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) _build/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in _build/doctest/output.txt." python-cymruwhois-1.6/docs/api.rst000066400000000000000000000001551277160004500173460ustar00rootroot00000000000000API --- .. autoclass:: cymruwhois.Client :members: lookup,lookupmany,lookupmany_dict :undoc-members: python-cymruwhois-1.6/docs/command_line.rst000066400000000000000000000020301277160004500212140ustar00rootroot00000000000000Command-line Interface ====================== The cymruwhois utility program lets you do lookups from the command line or shell scripts. Lookups can be done from stdin or from files:: justin@dell ~ % cat /tmp/ips | cymruwhois 15169 66.102.1.104 66.102.0.0/23 US GOOGLE - Google Inc. 22990 169.226.1.110 169.226.0.0/16 US ALBANYEDU - The University at Albany 12306 82.98.86.176 82.98.64.0/18 DE PLUSLINE Plus.Line AG IP-Services justin@dell ~ % cymruwhois /tmp/ips 15169 66.102.1.104 66.102.0.0/23 US GOOGLE - Google Inc. 22990 169.226.1.110 169.226.0.0/16 US ALBANYEDU - The University at Albany 12306 82.98.86.176 82.98.64.0/18 DE PLUSLINE Plus.Line AG IP-Services The formatting and contents of the output can be controlled with the -f and -d options:: justin@dell ~ % cymruwhois /tmp/ips -f asn,cc 15169 US 22990 US 12306 DE justin@dell ~ % cymruwhois /tmp/ips -f asn,cc -d, 15169,US 22990,US 12306,DE python-cymruwhois-1.6/docs/conf.py000066400000000000000000000143721277160004500173500ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # cymruwhois documentation build configuration file, created by # sphinx-quickstart on Sun Mar 22 00:26:37 2009. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('..')) # -- General configuration ----------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8' # The master toctree document. master_doc = 'index' # General information about the project. project = u'cymruwhois' copyright = u'2009, Justin Azoff' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '1.0' # The full version, including alpha/beta/rc tags. release = '1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of documents that shouldn't be included in the build. #unused_docs = [] # List of directories, relative to source directory, that shouldn't be searched # for source files. exclude_trees = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. Major themes that come with # Sphinx are currently 'default' and 'sphinxdoc'. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_use_modindex = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = '' # Output file base name for HTML help builder. htmlhelp_basename = 'cymruwhoisdoc' # -- Options for LaTeX output -------------------------------------------------- # The paper size ('letter' or 'a4'). #latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'cymruwhois.tex', ur'cymruwhois Documentation', ur'Justin Azoff', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # Additional stuff for the LaTeX preamble. #latex_preamble = '' # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_use_modindex = True python-cymruwhois-1.6/docs/cymruwhois.1000066400000000000000000000034101277160004500203330ustar00rootroot00000000000000.\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH CYMRUWHOIS 1 "February 26, 2009" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME cymruwhois \- program to lookup ip addresses using the cymru whois service .SH SYNOPSIS .B cymruwhois .RI [ options ] " files" ... .br .SH DESCRIPTION This manual page documents briefly the .B cymruwhois command. .PP .\" TeX users may be more comfortable with the \fB\fP and .\" \fI\fP escape sequences to invode bold face and italics, .\" respectively. \fBcymruwhois\fP is a program that... .SH OPTIONS This program follow the usual GNU command line syntax, with long options starting with two dashes (`-'). .TP .B \-h, \-\-help Show summary of options. .TP .B \-d DELIM, \-\-delim=DELIM delimiter to use instead of justified .TP .B \-f FIELDS, \-\-fields=FIELDS comma separated fields to include (asn,ip,prefix,cc,owner) .TP .B \-c CACHE, \-\-cache=CACHE memcache server (default localhost) .TP .B \-n, \-\-no-cache don't use memcached .SH SEE ALSO .BR whois (1), .br .SH AUTHOR cymruwhois was written by Justin Azoff .PP This manual page was written by Justin Azoff for the Debian project (but may be used by others). python-cymruwhois-1.6/docs/download.rst000066400000000000000000000004611277160004500204040ustar00rootroot00000000000000Downloading =========== Releases -------- released versions are available for download at the `Python Package Index `_. Source ------ The latest source code is avialable at the `github project page `_. python-cymruwhois-1.6/docs/index.rst000066400000000000000000000010041277160004500176760ustar00rootroot00000000000000.. cymruwhois documentation master file, created by sphinx-quickstart on Sun Mar 22 00:26:37 2009. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to cymruwhois's documentation! ====================================== cymruwhois is a python library for interfacing with the whois.cymru.com service. Contents: .. toctree:: :maxdepth: 2 api command_line download Indices and tables ================== * :ref:`genindex` python-cymruwhois-1.6/docs/make.bat000066400000000000000000000056271277160004500174610ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation set SPHINXBUILD=sphinx-build set ALLSPHINXOPTS=-d _build/doctrees %SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. changes to make an overview over all changed/added/deprecated items echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (_build\*) do rmdir /q /s %%i del /q /s _build\* goto end ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% _build/html echo. echo.Build finished. The HTML pages are in _build/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% _build/dirhtml echo. echo.Build finished. The HTML pages are in _build/dirhtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% _build/pickle echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% _build/json echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% _build/htmlhelp echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in _build/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% _build/qthelp echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in _build/qthelp, like this: echo.^> qcollectiongenerator _build\qthelp\cymruwhois.qhcp echo.To view the help file: echo.^> assistant -collectionFile _build\qthelp\cymruwhois.ghc goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% _build/latex echo. echo.Build finished; the LaTeX files are in _build/latex. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% _build/changes echo. echo.The overview file is in _build/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% _build/linkcheck echo. echo.Link check complete; look for any errors in the above output ^ or in _build/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% _build/doctest echo. echo.Testing of doctests in the sources finished, look at the ^ results in _build/doctest/output.txt. goto end ) :end python-cymruwhois-1.6/setup.py000066400000000000000000000025421277160004500166270ustar00rootroot00000000000000from setuptools import setup from glob import glob setup(name="cymruwhois", version="1.6", description="Client for the whois.cymru.com service", long_description=""" Perform lookups by ip address and return ASN, Country Code, and Netblock Owner:: >>> import socket >>> ip = socket.gethostbyname("www.google.com") >>> from cymruwhois import Client >>> c=Client() >>> r=c.lookup(ip) >>> print r.asn 15169 >>> print r.owner GOOGLE - Google Inc. """, url="http://packages.python.org/cymruwhois/", download_url="http://github.com/JustinAzoff/python-cymruwhois/tree/master", license='MIT', classifiers=[ "Topic :: System :: Networking", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Development Status :: 5 - Production/Stable", ], keywords='ASN', author="Justin Azoff", author_email="justin@bouncybouncy.net", py_modules = ["cymruwhois"], extras_require = { 'CACHE': ["python-memcached"], 'docs' : ['sphinx'], 'tests' : ['nose'], }, entry_points = { 'console_scripts': [ 'cymruwhois = cymruwhois:lookup_stdin', ] }, setup_requires=[ ], test_suite='nose.collector', ) python-cymruwhois-1.6/tests/000077500000000000000000000000001277160004500162545ustar00rootroot00000000000000python-cymruwhois-1.6/tests/test_common_lookups.py000066400000000000000000000011301277160004500227240ustar00rootroot00000000000000import cymruwhois import socket def test_common(): l=cymruwhois.Client() places = [ ['www.google.com', 'google'], ['www.yahoo.com', 'yahoo'], ['www.albany.edu', 'albany'], ] for hostname, owner in places: yield common_case, l, hostname, owner def test_asn(): l=cymruwhois.Client() record = l.lookup("AS15169") assert 'google' in record.owner.lower() def common_case(client, hostname, owner): ip = socket.gethostbyname(hostname) r=client.lookup(ip) print(owner, r.owner.lower()) assert owner in r.owner.lower() python-cymruwhois-1.6/tests/test_doctest.py000066400000000000000000000001601277160004500213270ustar00rootroot00000000000000import doctest, cymruwhois def test_doctest(): fail, ok = doctest.testmod(cymruwhois) assert fail == 0 python-cymruwhois-1.6/tests/test_mocked_socket.py000066400000000000000000000051271277160004500225040ustar00rootroot00000000000000import cymruwhois import socket import errno class FakeFile: def __init__(self, lines): self.lines = lines self.iter = iter(lines) self.written = [] def write(self, data): self.written.append(data) return def flush(self): return def readline(self): try : try: return self.iter.next() except AttributeError: return self.iter.__next__() # for Python 3 except StopIteration: raise socket.error(errno.EAGAIN, 'bleh') def read(self, bytes): try : try: return self.iter.next() except AttributeError: return self.iter.__next__() # for Python 3 except StopIteration: raise socket.error(errno.EAGAIN, 'bleh') class FakeSocket: def __init__(self): pass def setblocking(self,x): pass def test_normal(): l=cymruwhois.Client(memcache_host=None) l.socket = FakeSocket() l.file = FakeFile([ '22990 | 169.226.11.11 | 169.226.0.0/16 | US | ALBANYEDU - The University at Albany' ]) l._connected = True rec = l.lookup("169.226.11.11") assert rec.asn == '22990' assert rec.cc == 'US' assert rec.owner == 'ALBANYEDU - The University at Albany' def test_multiple_returned_for_a_single_ip(): l=cymruwhois.Client(memcache_host=None) l.socket = FakeSocket() l.file = FakeFile([ '22990 | 169.226.11.11 | 169.226.0.0/16 | US | ALBANYEDU - The University at Albany', '22991 | 169.226.11.11 | 169.226.0.0/16 | US | ALBANYEDU - The University at Albany', '15169 | 66.102.1.104 | 66.102.0.0/23 | US | GOOGLE - Google Inc.', ]) l._connected = True rec = l.lookup("169.226.11.11") assert rec.asn == '22990' rec = l.lookup("66.102.1.104") assert rec.asn == '15169' def test_multiple_returned_for_a_single_ip_dict(): l=cymruwhois.Client(memcache_host=None) l.socket = FakeSocket() l.file = FakeFile([ '22990 | 169.226.11.11 | 169.226.0.0/16 | US | ALBANYEDU - The University at Albany', '22991 | 169.226.11.11 | 169.226.0.0/16 | US | ALBANYEDU - The University at Albany', '15169 | 66.102.1.104 | 66.102.0.0/23 | US | GOOGLE - Google Inc.', ]) l._connected = True recs = l.lookupmany_dict(['169.226.11.11','66.102.1.104']) rec = recs['169.226.11.11'] assert rec.asn == '22990' rec = recs['66.102.1.104'] assert rec.asn == '15169'