From eb6cbc263608b1203534cb27de7614d703d9ff12 Mon Sep 17 00:00:00 2001 From: Shir Date: Sun, 6 May 2018 19:51:36 +0300 Subject: [PATCH] Initial Commit --- .gitignore | 3 -- __init__.py | 6 +++ events.py | 18 +++++++++ host_discovery.py | 16 ++++++++ kube_open_dashboard.py | 31 +++++++++++++++ main.py | 4 ++ modules/__init__.py | 6 +++ modules/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 315 bytes .../__pycache__/host_discovery.cpython-36.pyc | Bin 0 -> 1071 bytes .../kube_open_dashboard.cpython-36.pyc | Bin 0 -> 1155 bytes .../__pycache__/port_discovery.cpython-36.pyc | Bin 0 -> 1332 bytes modules/host_discovery.py | 16 ++++++++ modules/kube_open_dashboard.py | 31 +++++++++++++++ modules/port_discovery.py | 36 ++++++++++++++++++ port_discovery.py | 36 ++++++++++++++++++ 15 files changed, 200 insertions(+), 3 deletions(-) delete mode 100644 .gitignore create mode 100644 __init__.py create mode 100644 events.py create mode 100644 host_discovery.py create mode 100644 kube_open_dashboard.py create mode 100644 main.py create mode 100644 modules/__init__.py create mode 100644 modules/__pycache__/__init__.cpython-36.pyc create mode 100644 modules/__pycache__/host_discovery.cpython-36.pyc create mode 100644 modules/__pycache__/kube_open_dashboard.cpython-36.pyc create mode 100644 modules/__pycache__/port_discovery.cpython-36.pyc create mode 100644 modules/host_discovery.py create mode 100644 modules/kube_open_dashboard.py create mode 100644 modules/port_discovery.py create mode 100644 port_discovery.py diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 8c75de4..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.idea/ -__pycache__/ -*.pyc \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..440ff65 --- /dev/null +++ b/__init__.py @@ -0,0 +1,6 @@ +from .kube_open_dashboard import KubeOpenDashboard +from .port_discovery import PortDiscovery +from .host_discovery import HostDiscovery + +__all__ = [HostDiscovery, KubeOpenDashboard, PortDiscovery] + diff --git a/events.py b/events.py new file mode 100644 index 0000000..cc9f506 --- /dev/null +++ b/events.py @@ -0,0 +1,18 @@ +hooks = {} + + +def trigger_event(name, item): + print('Event Lookup: ', name, item) + if name in hooks: + for single_hook in hooks[name]: + print("Event triggerd!", single_hook, item) + single_hook(item).execute() + + +def register_event(name, callback): + print('NEW Event: ', name, callback) + if name not in hooks: + # default dict + hooks[name] = [] + if callback not in hooks[name]: + hooks[name].append(callback) diff --git a/host_discovery.py b/host_discovery.py new file mode 100644 index 0000000..e26e5b7 --- /dev/null +++ b/host_discovery.py @@ -0,0 +1,16 @@ +from netifaces import interfaces, ifaddresses, AF_INET +from netaddr import IPNetwork +import events + + +class HostDiscovery(object): + def __init__(self, task): + pass + + def execute(self): + for ifaceName in interfaces(): + addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [])] + if addresses: + subnet = IPNetwork('{0}/24'.format(addresses[0])) + for single_ip in IPNetwork(subnet): + events.trigger_event('NEW_HOST', {'host': single_ip}) diff --git a/kube_open_dashboard.py b/kube_open_dashboard.py new file mode 100644 index 0000000..56f2092 --- /dev/null +++ b/kube_open_dashboard.py @@ -0,0 +1,31 @@ +import events +import requests + + +class KubeOpenDashboard(object): + def __init__(self, task): + self.task = task + self.host = task['host'] + self.port = task['port'] or 80 + + pass + + def execute(self): + try: + r = requests.get("http://{host}:{port}/api/v1/node?itemsPerPage=100".format(host=self.host, port=self.port)) + except requests.exceptions.ConnectionError: + return None + + ret = r.json() + if 'listMeta' in ret: + print("KubeOpenDashboard :: Open Dashboard!", self.host) + + +events.register_event('OPEN_PORT_30000', KubeOpenDashboard) + +if __name__ == "__main__": + queue = list() + queue.append(KubeOpenDashboard({'host': '192.168.1.117', 'port': 30000})) + queue.append(KubeOpenDashboard({'host': '192.168.1.117', 'port': None})) + for i in queue: + i.execute() diff --git a/main.py b/main.py new file mode 100644 index 0000000..346e4c7 --- /dev/null +++ b/main.py @@ -0,0 +1,4 @@ +import modules + +modules.HostDiscovery({}).execute() + diff --git a/modules/__init__.py b/modules/__init__.py new file mode 100644 index 0000000..440ff65 --- /dev/null +++ b/modules/__init__.py @@ -0,0 +1,6 @@ +from .kube_open_dashboard import KubeOpenDashboard +from .port_discovery import PortDiscovery +from .host_discovery import HostDiscovery + +__all__ = [HostDiscovery, KubeOpenDashboard, PortDiscovery] + diff --git a/modules/__pycache__/__init__.cpython-36.pyc b/modules/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..94eb4c7a13ca9a418c50602c278949c53f982d23 GIT binary patch literal 315 zcmXr!<>jhZejjz3fq~&M5W@j8kmUfx#YR9Pg&~D8has0Sijfh-X3Am8WsYJ7vzc>P za#^ET85vSpQyEj4)0v~#Qdoi+G+AFV0ySzf-V*dKO-l7INX>IeEY3*EPb^9S3i1Zz z7nQhV7ANPIr506!1U&MK5dwai>`}tmKz;G~K#lP!Fr7tAKr^HG3V@p9Q((G_Ku(R~ z%K#dHB*+33yu}_LpO}*qAHR~Jhz-aG6TkGFtzyFSi?U-93riDYK(^>+l;)MB7U>$r nlIYq;;?~;+JQV&3^Ip@5eS(8Jxo@O literal 0 HcmV?d00001 diff --git a/modules/__pycache__/host_discovery.cpython-36.pyc b/modules/__pycache__/host_discovery.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4881d0beb08ea71fb8339629763a8acc700b6af1 GIT binary patch literal 1071 zcmZuvO;6iE5Z(3KjuVm|D%y&whe|#9K#G7<6`>+N3KzE$sFAE7*LXLD6=88-Ou!Bh(-PB_g- zPD7eop_Q|cQ9QFUJ9k2-^jYSH?gzqc?%WXWh{}wG9%o0ycYi?!;xkiA2U^H(oCsx> z(r(PT6iUISvb`T227AXoHPypUfzV$Ic^)Jfwip0!4(Am(f`pWl(BhO^HzZ`7aT``B zjpa<^pip`@RY`FvBPfP+&Leeiq*3bl2~2uL|iQsw_{(&mVwlE}kTa z2!{jaf|cmH;9PytWJY$$$>%AZ6V-G=XS8o=)*~}(m(1wYnpo1)HfMc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