Initial Commit

This commit is contained in:
Shir
2018-05-06 19:51:36 +03:00
parent cd880ec50e
commit eb6cbc2636
15 changed files with 200 additions and 3 deletions

3
.gitignore vendored
View File

@@ -1,3 +0,0 @@
.idea/
__pycache__/
*.pyc

6
__init__.py Normal file
View File

@@ -0,0 +1,6 @@
from .kube_open_dashboard import KubeOpenDashboard
from .port_discovery import PortDiscovery
from .host_discovery import HostDiscovery
__all__ = [HostDiscovery, KubeOpenDashboard, PortDiscovery]

18
events.py Normal file
View File

@@ -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)

16
host_discovery.py Normal file
View File

@@ -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})

31
kube_open_dashboard.py Normal file
View File

@@ -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()

4
main.py Normal file
View File

@@ -0,0 +1,4 @@
import modules
modules.HostDiscovery({}).execute()

6
modules/__init__.py Normal file
View File

@@ -0,0 +1,6 @@
from .kube_open_dashboard import KubeOpenDashboard
from .port_discovery import PortDiscovery
from .host_discovery import HostDiscovery
__all__ = [HostDiscovery, KubeOpenDashboard, PortDiscovery]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
modules/host_discovery.py Normal file
View File

@@ -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})

View File

@@ -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()

36
modules/port_discovery.py Normal file
View File

@@ -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()

36
port_discovery.py Normal file
View File

@@ -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()