mirror of
https://github.com/adulau/crl-monitor.git
synced 2024-11-21 17:47:09 +00:00
Add python client API
This commit is contained in:
parent
685b0b5ae9
commit
4d87f4fcb5
6 changed files with 116 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
build/
|
||||
dist/
|
||||
*.egg-info/
|
||||
|
27
client/LICENSE
Normal file
27
client/LICENSE
Normal file
|
@ -0,0 +1,27 @@
|
|||
Copyright (c) 2013, 2014 Raphaël Vinot
|
||||
Copyright (c) 2013, 2014 Alexandre Dulaunoy
|
||||
Copyright (c) 2013, 2014 CIRCL - Computer Incident Response Center Luxembourg
|
||||
(c/o smile, security made in Lëtzebuerg, Groupement
|
||||
d'Intérêt Economique)
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
OF THE POSSIBILITY OF SUCH DAMAGE.
|
11
client/README.md
Normal file
11
client/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
Client API for PSSL
|
||||
===================
|
||||
|
||||
Client API to query the Passive SSL implementation provided by CIRCL.
|
||||
|
||||
Passive DNS Services
|
||||
====================
|
||||
|
||||
* (default) [CIRCL Passive SSL](http://circl.lu/services/passive-ssl/)
|
||||
|
||||
|
1
client/pypssl/__init__.py
Normal file
1
client/pypssl/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from api import PyPSSL
|
47
client/pypssl/api.py
Normal file
47
client/pypssl/api.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import requests
|
||||
import socket
|
||||
|
||||
|
||||
class PyPSSL(object):
|
||||
|
||||
def __init__(self, url='https://www.circl.lu/pssl/query', basic_auth=None,
|
||||
auth_token=None):
|
||||
self.url = url
|
||||
|
||||
self.session = requests.Session()
|
||||
if basic_auth is not None:
|
||||
# basic_auth has do be a tuple ('user_name', 'password')
|
||||
self.session.auth = basic_auth
|
||||
elif auth_token is not None:
|
||||
self.session.headers.update({'Authorization': auth_token})
|
||||
else:
|
||||
# No authentication defined.
|
||||
pass
|
||||
|
||||
def _check_IP(self, ip):
|
||||
if ':' in ip:
|
||||
return {'error': 'IPv6 is not (yet) supported'}
|
||||
splitted = ip.split('/')
|
||||
try:
|
||||
if len(splitted) == 2:
|
||||
ip, block = splitted
|
||||
if int(block) < 23:
|
||||
return {'error': 'Maximum CIDR block size reached >/23'}
|
||||
socket.inet_aton(ip)
|
||||
except:
|
||||
return {'error': 'Incorrect format'}
|
||||
return None
|
||||
|
||||
def query(self, q):
|
||||
check = self._check_IP(q)
|
||||
if check is not None:
|
||||
return check
|
||||
response = self.session.get('{}/{}' .format(self.url, q))
|
||||
try:
|
||||
return response.json()
|
||||
except:
|
||||
raise Exception('Unable to decode JSON object: ' + response.text)
|
||||
return {}
|
26
client/setup.py
Normal file
26
client/setup.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='pypssl',
|
||||
version='1.0',
|
||||
author='Raphaël Vinot',
|
||||
author_email='raphael.vinot@circl.lu',
|
||||
maintainer='Raphaël Vinot',
|
||||
url='https://github.com/CIRCL/PyPSSL',
|
||||
description='Python API for PSSL.',
|
||||
long_description=open('README.md').read(),
|
||||
packages=['pypssl'],
|
||||
classifiers=[
|
||||
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
|
||||
'Development Status :: 3 - Alpha',
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: Science/Research',
|
||||
'Intended Audience :: Telecommunications Industry',
|
||||
'Programming Language :: Python',
|
||||
'Topic :: Security',
|
||||
'Topic :: Internet',
|
||||
],
|
||||
install_requires=['requests'],
|
||||
)
|
Loading…
Reference in a new issue