├── tests ├── __init__.py ├── test_robtex_python.py └── test_robtex_cli.py ├── .codacy.yml ├── mypy.ini ├── requirements.txt ├── .coveragerc ├── robtex_python ├── __init__.py ├── requester.py ├── robtex_python.py └── cli.py ├── bumpversion.dockerfile ├── Dockerfile ├── .travis.yml ├── requirements_dev.txt ├── MANIFEST.in ├── docker └── lint.sh ├── .github ├── ISSUE_TEMPLATE.md └── workflows │ └── python-publish.yml ├── .editorconfig ├── setup.cfg ├── pyproject.toml ├── docker-compose.yml ├── LICENSE ├── setup.py ├── .gitignore ├── README.rst ├── Makefile └── CONTRIBUTING.rst /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.codacy.yml: -------------------------------------------------------------------------------- 1 | exclude_paths: 2 | - tests/** -------------------------------------------------------------------------------- /mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | ignore_missing_imports = True 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | docopt>=0.6 2 | requests==2.* 3 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | .tox/* 4 | tests/* 5 | setup.py 6 | travis_pypi_setup.py -------------------------------------------------------------------------------- /robtex_python/__init__.py: -------------------------------------------------------------------------------- 1 | from .robtex_python import as_query, ip_query, pdns_forward, pdns_reverse # noqa: F401 2 | 3 | __author__ = "Floyd Hightower" 4 | __version__ = '1.2.0' 5 | -------------------------------------------------------------------------------- /bumpversion.dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9.1-buster 2 | 3 | ENV PIP_NO_CACHE_DIR "true" 4 | 5 | COPY ./requirements*.txt /code/ 6 | 7 | WORKDIR /code 8 | 9 | RUN pip install bump2version 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9.1-buster 2 | 3 | ENV PIP_NO_CACHE_DIR "true" 4 | 5 | COPY ./requirements*.txt /code/ 6 | 7 | WORKDIR /code 8 | 9 | RUN pip install -r requirements.txt -r requirements_dev.txt 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | after_success: 2 | - codecov 3 | install: 4 | - pip install pytest 5 | - pip install pytest-cov 6 | - pip install codecov 7 | - pip install docopt 8 | - pip install requests 9 | language: python 10 | python: 3.7 11 | script: 12 | - py.test --cov=./ 13 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | bandit 2 | black; python_version > '3.5' 3 | codecov 4 | flake8 5 | flake8-cognitive-complexity 6 | ipython 7 | mypy 8 | pylint 9 | pytest 10 | pytest-cov 11 | d8s-python==0.* 12 | d8s-file-system==0.* 13 | d8s-strings==0.* 14 | bump2version 15 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | 2 | include AUTHORS.rst 3 | 4 | include CONTRIBUTING.rst 5 | include HISTORY.rst 6 | include LICENSE 7 | include README.rst 8 | 9 | recursive-include tests * 10 | recursive-exclude * __pycache__ 11 | recursive-exclude * *.py[co] 12 | 13 | recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif 14 | -------------------------------------------------------------------------------- /docker/lint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euxo pipefail 4 | 5 | echo "Running linters and formatters..." 6 | 7 | isort robtex_python/ tests/ 8 | 9 | black robtex_python/ tests/ 10 | 11 | mypy robtex_python/ tests/ 12 | 13 | pylint --fail-under 9 robtex_python/*.py 14 | 15 | flake8 robtex_python/ tests/ 16 | 17 | bandit -r robtex_python/ 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * Robtex Python version: 2 | * Python version: 3 | * Operating System: 4 | 5 | ### Description 6 | 7 | Describe what you were trying to get done. 8 | Tell us what happened, what went wrong, and what you expected to happen. 9 | 10 | ### What I Did 11 | 12 | ``` 13 | Paste the command(s) you ran and the output. 14 | If there was a crash, please include the traceback here. 15 | ``` 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 4 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | charset = utf-8 11 | end_of_line = lf 12 | 13 | [*.bat] 14 | indent_style = tab 15 | end_of_line = crlf 16 | 17 | [LICENSE] 18 | insert_final_newline = false 19 | 20 | [Makefile] 21 | indent_style = tab 22 | 23 | [{.travis.yml}] 24 | indent_style = space 25 | indent_size = 2 26 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 1.2.0 3 | commit = True 4 | tag = True 5 | 6 | [bumpversion:file:setup.py] 7 | search = version='{current_version}' 8 | replace = version='{new_version}' 9 | 10 | [bumpversion:file:robtex_python/__init__.py] 11 | search = __version__ = '{current_version}' 12 | replace = __version__ = '{new_version}' 13 | 14 | [bdist_wheel] 15 | universal = 1 16 | 17 | [flake8] 18 | max-line-length = 120 19 | per-file-ignores = 20 | d8s_algorithms/__init__.py:F403,F401 21 | tests/*:E501 22 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 120 3 | skip-string-normalization = true 4 | 5 | [tool.isort] 6 | line_length = 120 7 | include_trailing_comma = true 8 | 9 | [tool.pylint."MESSAGES CONTROL"] 10 | max-line-length = 120 11 | disable = "C0114, R1705, C0103, C0415" 12 | 13 | [tool.pytest.ini_options] 14 | addopts = "-v --cov=. --cov-report term-missing --cov-fail-under 90" 15 | python_files = "tests/test_*.py" 16 | 17 | [build-system] 18 | requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] 19 | 20 | [tool.setuptools_scm] 21 | -------------------------------------------------------------------------------- /robtex_python/requester.py: -------------------------------------------------------------------------------- 1 | """Make and handle requests.""" 2 | 3 | import json 4 | 5 | import requests 6 | 7 | 8 | def get(api_path): 9 | """Request the api path and return the response.""" 10 | response = requests.get(api_path) 11 | 12 | if response.ok: 13 | try: 14 | # return the json from the API endpoint 15 | return json.loads(response.text) 16 | except ValueError: 17 | # handle the list of dictionaries returned from the pdns endpoints 18 | return [json.loads(entry) for entry in response.text.split("\r\n") if entry != ''] 19 | else: 20 | # print information about the error 21 | print("{} error retrieving {}: {}".format(response.status_code, api_path, response.text)) 22 | return None 23 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | 3 | services: 4 | _base: 5 | &base 6 | build: 7 | dockerfile: Dockerfile 8 | context: . 9 | volumes: 10 | - ./:/code 11 | 12 | _bump-base: 13 | &bump-base 14 | build: 15 | dockerfile: bumpversion.dockerfile 16 | context: . 17 | volumes: 18 | - ./:/code 19 | - ~/.gitconfig:/root/.gitconfig 20 | 21 | bump-patch: 22 | <<: *bump-base 23 | command: bumpversion patch 24 | 25 | bump-minor: 26 | <<: *bump-base 27 | command: bumpversion minor 28 | 29 | bump-major: 30 | <<: *bump-base 31 | command: bumpversion major 32 | 33 | # a fully loaded development environment to test new code 34 | dev: 35 | <<: *base 36 | command: ipython 37 | 38 | # run tests 39 | test: 40 | <<: *base 41 | command: pytest 42 | 43 | # run linters 44 | lint: 45 | <<: *base 46 | entrypoint: ./docker/lint.sh 47 | -------------------------------------------------------------------------------- /robtex_python/robtex_python.py: -------------------------------------------------------------------------------- 1 | """Wrapper for the Robtex API.""" 2 | 3 | from .requester import get 4 | 5 | BASE_API_URL = "https://freeapi.robtex.com/" 6 | 7 | 8 | def ip_query(ip_address): 9 | """Get the current forward and reverse of an IP number, together with GEO-location data and network data.""" 10 | response = get(BASE_API_URL + "ipquery/{}".format(ip_address)) 11 | return response 12 | 13 | 14 | def as_query(as_number): 15 | """Get the networks actually in global bgp table (plans to expand this in the future).""" 16 | response = get(BASE_API_URL + "asquery/{}".format(as_number)) 17 | return response 18 | 19 | 20 | def pdns_forward(hostname): 21 | """Get the IP addresses to which the given host has resolved.""" 22 | response = get(BASE_API_URL + "pdns/forward/{}".format(hostname)) 23 | return response 24 | 25 | 26 | def pdns_reverse(ip_address): 27 | """Get the reverse pdns for the given IP address.""" 28 | response = get(BASE_API_URL + "pdns/reverse/{}".format(ip_address)) 29 | return response 30 | -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will upload a Python Package using Twine when a release is created 2 | # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries 3 | 4 | name: Upload Python Package to PyPi 5 | 6 | on: 7 | push: 8 | tags: 9 | - 'v*' 10 | release: 11 | types: [published] 12 | 13 | jobs: 14 | deploy: 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Set up Python 21 | uses: actions/setup-python@v2 22 | with: 23 | python-version: '3.x' 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install --upgrade pip 27 | pip install setuptools wheel twine 28 | - name: Build and publish 29 | env: 30 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} 31 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 32 | run: | 33 | python setup.py sdist bdist_wheel 34 | twine upload dist/* 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017, Floyd Hightower 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | 2 | from setuptools import setup, find_packages 3 | 4 | with open('README.rst') as readme_file: 5 | readme = readme_file.read() 6 | 7 | requirements = [ 8 | 'docopt>=0.6', 9 | 'requests' 10 | ] 11 | 12 | test_requirements = [ 13 | # TODO: put package test requirements here 14 | ] 15 | 16 | setup( 17 | name='robtex_python', 18 | version='1.2.0', 19 | description="Simple python wrapper for the Robtex API.", 20 | long_description=readme, 21 | author="Floyd Hightower", 22 | author_email='', 23 | url='https://github.com/fhightower/robtex-python', 24 | packages=find_packages(exclude=('tests', 'docs')), 25 | entry_points={ 26 | 'console_scripts': [ 27 | 'robtex_python=robtex_python.cli:main' 28 | ] 29 | }, 30 | include_package_data=True, 31 | install_requires=requirements, 32 | license='MIT License', 33 | zip_safe=True, 34 | keywords='robtex', 35 | classifiers=[ 36 | 'Development Status :: 4 - Beta', 37 | 'Intended Audience :: Developers', 38 | 'License :: OSI Approved :: MIT License', 39 | 'Natural Language :: English', 40 | 'Programming Language :: Python :: 3', 41 | 'Programming Language :: Python :: 3.3', 42 | 'Programming Language :: Python :: 3.4', 43 | 'Programming Language :: Python :: 3.5', 44 | ], 45 | test_suite='tests', 46 | tests_require=test_requirements 47 | ) 48 | -------------------------------------------------------------------------------- /tests/test_robtex_python.py: -------------------------------------------------------------------------------- 1 | """ 2 | test_robtex_python 3 | ---------------------------------- 4 | 5 | Tests for `robtex_python` module. 6 | """ 7 | 8 | import pytest 9 | 10 | import robtex_python 11 | 12 | 13 | @pytest.fixture 14 | def command_line_args(): 15 | """Function to simulate command line arguments using docopt.""" 16 | args = dict() 17 | 18 | args['ip'] = "8.8.8.8" 19 | args['asn'] = "15169" 20 | args['host'] = "example.com" 21 | 22 | return args 23 | 24 | 25 | def test_ip_query(command_line_args): 26 | """Test the ip query.""" 27 | response = robtex_python.ip_query(command_line_args['ip']) 28 | 29 | assert response['status'] == "ok" 30 | assert response['city'] == "Mountain View" 31 | 32 | 33 | def test_as_query(command_line_args): 34 | """Test the asn query.""" 35 | response = robtex_python.as_query(command_line_args['asn']) 36 | 37 | assert response['status'] == "ok" 38 | 39 | 40 | def test_pdns_forward_query(command_line_args): 41 | """Test the pdns forward query.""" 42 | response = robtex_python.pdns_forward(command_line_args['host']) 43 | 44 | assert len(response) > 1 45 | assert response[0]['rrname'] == command_line_args['host'] 46 | 47 | 48 | def test_pdns_reverse_query(command_line_args): 49 | """Test the pdns reverse query.""" 50 | response = robtex_python.pdns_reverse(command_line_args['ip']) 51 | 52 | assert len(response) > 1 53 | assert response[0]['rrdata'] == command_line_args['ip'] 54 | -------------------------------------------------------------------------------- /robtex_python/cli.py: -------------------------------------------------------------------------------- 1 | """Robtex Python. 2 | 3 | Usage: 4 | robtex_python --ip= 5 | robtex_python --as= 6 | robtex_python --pdns-forward= 7 | robtex_python --pdns-reverse= 8 | robtex_python (-h | --help) 9 | robtex_python --version 10 | 11 | Options: 12 | -h --help Show this screen. 13 | --version Show version. 14 | --ip= IP Address. 15 | --as= ASN. 16 | --pdns-forward= pDNS Forward Hostname. 17 | --pdns-reverse= pDNS Reverse IP Address. 18 | """ 19 | 20 | from docopt import docopt 21 | 22 | from .__init__ import __version__ as VERSION 23 | from .robtex_python import as_query, ip_query, pdns_forward, pdns_reverse 24 | 25 | 26 | def main(arguments=None): 27 | """Console script for robtex_python""" 28 | if arguments is None: 29 | arguments = docopt(__doc__, version=VERSION) 30 | else: 31 | # if there are values passed into this function for testing, move along 32 | pass 33 | 34 | if arguments.get('--ip'): 35 | output = ip_query(arguments['--ip']) 36 | print(output) 37 | return output 38 | elif arguments.get('--as'): 39 | output = as_query(arguments['--as']) 40 | print(output) 41 | return output 42 | elif arguments.get('--pdns-forward'): 43 | output = pdns_forward(arguments['--pdns-forward']) 44 | print(output) 45 | return output 46 | elif arguments.get('--pdns-reverse'): 47 | output = pdns_reverse(arguments['--pdns-reverse']) 48 | print(output) 49 | return output 50 | 51 | 52 | if __name__ == "__main__": 53 | main() 54 | -------------------------------------------------------------------------------- /tests/test_robtex_cli.py: -------------------------------------------------------------------------------- 1 | """ 2 | test_robtex_cli 3 | ---------------------------------- 4 | 5 | Tests for `robtex_python` cli interface. 6 | """ 7 | 8 | import docopt 9 | import pytest 10 | 11 | from robtex_python import cli 12 | 13 | 14 | @pytest.fixture 15 | def command_line_args(): 16 | """Function to simulate command line arguments using docopt.""" 17 | args = dict() 18 | 19 | args['ip'] = "8.8.8.8" 20 | args['asn'] = "15169" 21 | args['host'] = "example.com" 22 | 23 | return args 24 | 25 | 26 | def test_blank_command_line(): 27 | """Test the command line usage of this project.""" 28 | with pytest.raises(docopt.DocoptExit) as exc_info: 29 | cli.main() 30 | 31 | # get the error message 32 | error_message = exc_info.value 33 | # make sure the error message contains the expected usage output 34 | assert "Usage:" in str(error_message) 35 | 36 | 37 | def test_ip_query(): 38 | """Test the command line usage of this project.""" 39 | output = cli.main({'--ip': "8.8.8.8"}) 40 | 41 | assert output['status'] == "ok" 42 | assert output['city'] == "Mountain View" 43 | 44 | 45 | def test_as_query(): 46 | """Test the asn query.""" 47 | output = cli.main({'--as': "15169"}) 48 | 49 | assert output['status'] == "ok" 50 | 51 | 52 | def test_pdns_forward_query(command_line_args): 53 | """Test the pdns forward query.""" 54 | output = cli.main({'--pdns-forward': "example.com"}) 55 | 56 | assert len(output) > 1 57 | assert output[0]['rrname'] == command_line_args['host'] 58 | 59 | 60 | def test_pdns_reverse_query(command_line_args): 61 | """Test the pdns reverse query.""" 62 | output = cli.main({'--pdns-reverse': "8.8.8.8"}) 63 | 64 | assert len(output) > 1 65 | assert output[0]['rrdata'] == command_line_args['ip'] 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | 137 | # Cython debug symbols 138 | cython_debug/ 139 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ************* 2 | Robtex Python 3 | ************* 4 | 5 | .. image:: https://img.shields.io/pypi/v/robtex_python.svg 6 | :target: https://pypi.python.org/pypi/robtex_python 7 | 8 | .. image:: https://img.shields.io/travis/fhightower/robtex-python.svg 9 | :target: https://travis-ci.org/fhightower/robtex-python 10 | 11 | .. image:: https://codecov.io/gh/fhightower/robtex-python/branch/master/graph/badge.svg 12 | :target: https://codecov.io/gh/fhightower/robtex-python 13 | 14 | .. image:: https://api.codacy.com/project/badge/Grade/8151c710cd704ddeb8575ee6dfbbd96e 15 | :target: https://www.codacy.com/app/fhightower/robtex-python 16 | 17 | Simple python wrapper for the `Robtex API `_ . 18 | 19 | Installation 20 | ============ 21 | 22 | Stable release 23 | -------------- 24 | 25 | To install Robtex Python, run this command in your terminal: 26 | 27 | .. code-block:: console 28 | 29 | pip install robtex-python 30 | 31 | This is the preferred method to install the Robtex API wrapper, as it will always install the most recent stable release. 32 | 33 | If you don't have `pip`_ installed, this `Python installation guide`_ can guide 34 | you through the process. 35 | 36 | .. _pip: https://pip.pypa.io 37 | .. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/ 38 | 39 | From sources 40 | ------------ 41 | 42 | The sources for Robtex Python can be downloaded from the `Github repo`_. 43 | 44 | You can either clone the public repository: 45 | 46 | .. code-block:: console 47 | 48 | $ git clone git://github.com/fhightower/robtex-python 49 | 50 | Or download the `tarball`_: 51 | 52 | .. code-block:: console 53 | 54 | $ curl -OL https://github.com/fhightower/robtex-python/tarball/master 55 | 56 | Once you have a copy of the source, you can install it with: 57 | 58 | .. code-block:: console 59 | 60 | $ python3 setup.py install 61 | 62 | .. _Github repo: https://github.com/fhightower/robtex-python 63 | .. _tarball: https://github.com/fhightower/robtex-python/tarball/master 64 | 65 | Usage 66 | ===== 67 | 68 | Via Python 69 | ---------- 70 | 71 | You can use Robtex Python in a script as follows: 72 | 73 | .. code-block:: python 74 | 75 | import robtex_python 76 | response = robtex_python.pdns_forward("example.com") 77 | 78 | Via Command Line 79 | ---------------- 80 | 81 | You can use Robtex Python as a command-line tool as follows: 82 | 83 | .. code-block:: shell 84 | 85 | Usage: 86 | robtex_python --ip= 87 | robtex_python --as= 88 | robtex_python --pdns-forward= 89 | robtex_python --pdns-reverse= 90 | robtex_python (-h | --help) 91 | robtex_python --version 92 | 93 | Credits 94 | ======= 95 | 96 | This package was created with Cookiecutter_ and the `fhightower/python-project-template`_ project template. 97 | 98 | .. _Cookiecutter: https://github.com/audreyr/cookiecutter 99 | .. _`fhightower/python-project-template`: https://github.com/fhightower/python-project-template 100 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean clean-test clean-pyc clean-build docs help 2 | .DEFAULT_GOAL := help 3 | define BROWSER_PYSCRIPT 4 | import os, webbrowser, sys 5 | try: 6 | from urllib import pathname2url 7 | except: 8 | from urllib.request import pathname2url 9 | 10 | webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) 11 | endef 12 | export BROWSER_PYSCRIPT 13 | 14 | define PRINT_HELP_PYSCRIPT 15 | import re, sys 16 | 17 | for line in sys.stdin: 18 | match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) 19 | if match: 20 | target, help = match.groups() 21 | print("%-20s %s" % (target, help)) 22 | endef 23 | export PRINT_HELP_PYSCRIPT 24 | BROWSER := python -c "$$BROWSER_PYSCRIPT" 25 | 26 | help: 27 | @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) 28 | 29 | clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts 30 | 31 | 32 | clean-build: ## remove build artifacts 33 | rm -fr build/ 34 | rm -fr dist/ 35 | rm -fr .eggs/ 36 | find . -name '*.egg-info' -exec rm -fr {} + 37 | find . -name '*.egg' -exec rm -f {} + 38 | 39 | clean-pyc: ## remove Python file artifacts 40 | find . -name '*.pyc' -exec rm -f {} + 41 | find . -name '*.pyo' -exec rm -f {} + 42 | find . -name '*~' -exec rm -f {} + 43 | find . -name '__pycache__' -exec rm -fr {} + 44 | 45 | clean-test: ## remove test and coverage artifacts 46 | rm -fr .tox/ 47 | rm -f .coverage 48 | rm -fr htmlcov/ 49 | 50 | lint: ## check style with flake8 51 | flake8 robtex_python tests 52 | 53 | test: ## run tests quickly with the default Python 54 | py.test 55 | 56 | 57 | test-all: ## run tests on every Python version with tox 58 | tox 59 | 60 | coverage: ## check code coverage quickly with the default Python 61 | coverage run --source robtex_python -m pytest 62 | 63 | coverage report -m 64 | coverage html 65 | $(BROWSER) htmlcov/index.html 66 | 67 | docs: ## generate Sphinx HTML documentation, including API docs 68 | rm -f docs/robtex_python.rst 69 | rm -f docs/modules.rst 70 | sphinx-apidoc -o docs/ robtex_python 71 | $(MAKE) -C docs clean 72 | $(MAKE) -C docs html 73 | $(BROWSER) docs/_build/html/index.html 74 | 75 | servedocs: docs ## compile the docs watching for changes 76 | watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . 77 | 78 | release: clean ## package and upload a release 79 | python setup.py sdist upload 80 | python setup.py bdist_wheel upload 81 | 82 | dist: clean ## builds source and wheel package 83 | python setup.py sdist 84 | python setup.py bdist_wheel 85 | ls -l dist 86 | 87 | install: clean ## install the package to the active Python's site-packages 88 | python setup.py install 89 | 90 | upstream: ## set the upstream for the repository 91 | git remote set-upstream https://github.com/fhightower/robtex-python.git 92 | 93 | init: ## install the development requirements with pip (related to python2.x) 94 | pip install -r requirements_dev.txt 95 | 96 | init3: ## install the development requirements with pip3 (related to python3.x) 97 | pip3 install -r requirements_dev.txt 98 | 99 | pypi: clean ## upload the code to pypi 100 | python3 setup.py sdist bdist_wheel 101 | python3 -m twine upload dist/* 102 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: shell 2 | 3 | ************ 4 | Contributing 5 | ************ 6 | 7 | Contributions are welcome, and they are greatly appreciated! Every 8 | little bit helps, and credit will always be given. 9 | 10 | You can contribute in many ways: 11 | 12 | Types of Contributions 13 | ====================== 14 | 15 | Report Bugs 16 | ----------- 17 | 18 | Report bugs at https://github.com/fhightower/robtex-python/issues. 19 | 20 | If you are reporting a bug, please include: 21 | 22 | * Your operating system name and version. 23 | * Any details about your local setup that might be helpful in troubleshooting. 24 | * Detailed steps to reproduce the bug. 25 | 26 | Fix Bugs 27 | -------- 28 | 29 | Look through the GitHub issues for bugs. Anything tagged with "bug" 30 | and "help wanted" is open to whoever wants to implement it. 31 | 32 | Implement Features 33 | ------------------ 34 | 35 | Look through the GitHub issues for features. Anything tagged with "enhancement" 36 | and "help wanted" is open to whoever wants to implement it. 37 | 38 | Write Documentation 39 | ------------------- 40 | 41 | Robtex Python could always use more documentation, whether as part of the 42 | official Robtex Python docs, in docstrings, or even on the web in blog posts, 43 | articles, and such. 44 | 45 | Submit Feedback 46 | --------------- 47 | 48 | The best way to send feedback is to file an issue at https://github.com/fhightower/robtex-python/issues. 49 | 50 | If you are proposing a feature: 51 | 52 | * Explain in detail how it would work. 53 | * Keep the scope as narrow as possible, to make it easier to implement. 54 | * Remember that this is a volunteer-driven project, and that contributions 55 | are welcome :) 56 | 57 | Get Started! 58 | ============== 59 | 60 | Ready to contribute? Here's how to set up `robtex_python` for local development. 61 | 62 | 1. Fork the `robtex_python` repo on GitHub. 63 | 2. Clone your fork locally:: 64 | 65 | $ git clone git@github.com:/robtex_python.git 66 | 67 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 68 | 69 | $ mkvirtualenv robtex_python 70 | $ cd robtex_python/ 71 | $ python setup.py develop 72 | 73 | 4. Create a branch for local development:: 74 | 75 | $ git checkout -b name-of-your-bugfix-or-feature 76 | 77 | Now you can make your changes locally. 78 | 79 | 5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: 80 | 81 | $ flake8 robtex_python tests 82 | $ python setup.py test or py.test 83 | $ tox 84 | 85 | To get flake8 and tox, just pip install them into your virtualenv. 86 | 87 | 6. Commit your changes and push your branch to GitHub:: 88 | 89 | $ git add . 90 | $ git commit -m "Your detailed description of your changes." 91 | $ git push origin name-of-your-bugfix-or-feature 92 | 93 | 7. Submit a pull request through the GitHub website. 94 | 95 | Pull Request Guidelines 96 | ======================= 97 | 98 | Before you submit a pull request, check that it meets these guidelines: 99 | 100 | 1. The pull request should include tests. 101 | 2. If the pull request adds functionality, the docs should be updated. Put 102 | your new functionality into a function with a docstring, and add the 103 | feature to the list in README.rst. 104 | 3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check 105 | https://travis-ci.org/fhightower/robtex-python/pull_requests 106 | and make sure that the tests pass for all supported Python versions. 107 | 108 | Tips 109 | ---- 110 | 111 | To run a subset of tests:: 112 | 113 | $ py.test tests.test_robtex_python 114 | 115 | --------------------------------------------------------------------------------