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 0000000..94eb4c7 Binary files /dev/null and b/modules/__pycache__/__init__.cpython-36.pyc differ diff --git a/modules/__pycache__/host_discovery.cpython-36.pyc b/modules/__pycache__/host_discovery.cpython-36.pyc new file mode 100644 index 0000000..4881d0b Binary files /dev/null and b/modules/__pycache__/host_discovery.cpython-36.pyc differ diff --git a/modules/__pycache__/kube_open_dashboard.cpython-36.pyc b/modules/__pycache__/kube_open_dashboard.cpython-36.pyc new file mode 100644 index 0000000..651003b Binary files /dev/null and b/modules/__pycache__/kube_open_dashboard.cpython-36.pyc differ diff --git a/modules/__pycache__/port_discovery.cpython-36.pyc b/modules/__pycache__/port_discovery.cpython-36.pyc new file mode 100644 index 0000000..cf0d4d1 Binary files /dev/null and b/modules/__pycache__/port_discovery.cpython-36.pyc differ diff --git a/modules/host_discovery.py b/modules/host_discovery.py new file mode 100644 index 0000000..e26e5b7 --- /dev/null +++ b/modules/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/modules/kube_open_dashboard.py b/modules/kube_open_dashboard.py new file mode 100644 index 0000000..56f2092 --- /dev/null +++ b/modules/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/modules/port_discovery.py b/modules/port_discovery.py new file mode 100644 index 0000000..196854a --- /dev/null +++ b/modules/port_discovery.py @@ -0,0 +1,36 @@ +from socket import socket +import events + +default_ports = [8001, 10250, 10255, 30000] + + +class PortDiscovery(object): + def __init__(self, task): + self.host = task['host'] + + def execute(self): + for single_port in default_ports: + if self.test_connection(self.host, single_port): + events.trigger_event('OPEN_PORT', {'host': self.host, 'port': single_port}) + events.trigger_event('OPEN_PORT_{port}'.format(port=single_port), + {'host': self.host, 'port': single_port}) + + @staticmethod + def test_connection(host, port): + s = socket() + s.settimeout(1) + success = s.connect_ex((str(host), port)) + s.close() + if success == 0: + return True + return False + + +events.register_event('NEW_HOST', PortDiscovery) + +if __name__ == "__main__": + queue = list() + queue.append(PortDiscovery({'host': '192.168.1.117'})) + queue.append(PortDiscovery({'host': '192.168.1.101'})) + for i in queue: + i.execute() diff --git a/port_discovery.py b/port_discovery.py new file mode 100644 index 0000000..196854a --- /dev/null +++ b/port_discovery.py @@ -0,0 +1,36 @@ +from socket import socket +import events + +default_ports = [8001, 10250, 10255, 30000] + + +class PortDiscovery(object): + def __init__(self, task): + self.host = task['host'] + + def execute(self): + for single_port in default_ports: + if self.test_connection(self.host, single_port): + events.trigger_event('OPEN_PORT', {'host': self.host, 'port': single_port}) + events.trigger_event('OPEN_PORT_{port}'.format(port=single_port), + {'host': self.host, 'port': single_port}) + + @staticmethod + def test_connection(host, port): + s = socket() + s.settimeout(1) + success = s.connect_ex((str(host), port)) + s.close() + if success == 0: + return True + return False + + +events.register_event('NEW_HOST', PortDiscovery) + +if __name__ == "__main__": + queue = list() + queue.append(PortDiscovery({'host': '192.168.1.117'})) + queue.append(PortDiscovery({'host': '192.168.1.101'})) + for i in queue: + i.execute()