sciveo 0.1.8__tar.gz → 0.1.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {sciveo-0.1.8 → sciveo-0.1.10}/PKG-INFO +1 -1
  2. sciveo-0.1.10/sciveo/cli.py +59 -0
  3. sciveo-0.1.10/sciveo/monitoring/network.py +95 -0
  4. sciveo-0.1.10/sciveo/version.py +2 -0
  5. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo.egg-info/PKG-INFO +1 -1
  6. sciveo-0.1.8/sciveo/cli.py +0 -39
  7. sciveo-0.1.8/sciveo/monitoring/network.py +0 -130
  8. sciveo-0.1.8/sciveo/version.py +0 -2
  9. {sciveo-0.1.8 → sciveo-0.1.10}/README.md +0 -0
  10. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/__init__.py +0 -0
  11. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/api/__init__.py +0 -0
  12. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/api/base.py +0 -0
  13. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/api/upload.py +0 -0
  14. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/__init__.py +0 -0
  15. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/configuration.py +0 -0
  16. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/model.py +0 -0
  17. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/optimizers.py +0 -0
  18. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/sampling.py +0 -0
  19. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/__init__.py +0 -0
  20. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/configuration.py +0 -0
  21. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/daemon.py +0 -0
  22. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/formating.py +0 -0
  23. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/hardware.py +0 -0
  24. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/logger.py +0 -0
  25. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/synchronized.py +0 -0
  26. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/common/tools/timers.py +0 -0
  27. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/content/__init__.py +0 -0
  28. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/content/dataset.py +0 -0
  29. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/content/experiment.py +0 -0
  30. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/content/project.py +0 -0
  31. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/content/runner.py +0 -0
  32. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/monitoring/__init__.py +0 -0
  33. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/monitoring/monitor.py +0 -0
  34. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo/monitoring/start.py +0 -0
  35. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo.egg-info/SOURCES.txt +0 -0
  36. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo.egg-info/dependency_links.txt +0 -0
  37. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo.egg-info/entry_points.txt +0 -0
  38. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo.egg-info/requires.txt +0 -0
  39. {sciveo-0.1.8 → sciveo-0.1.10}/sciveo.egg-info/top_level.txt +0 -0
  40. {sciveo-0.1.8 → sciveo-0.1.10}/setup.cfg +0 -0
  41. {sciveo-0.1.8 → sciveo-0.1.10}/setup.py +0 -0
  42. {sciveo-0.1.8 → sciveo-0.1.10}/test/test_configuration.py +0 -0
  43. {sciveo-0.1.8 → sciveo-0.1.10}/test/test_monitoring.py +0 -0
  44. {sciveo-0.1.8 → sciveo-0.1.10}/test/test_runner.py +0 -0
  45. {sciveo-0.1.8 → sciveo-0.1.10}/test/test_sampling.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.8
3
+ Version: 0.1.10
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # Pavlin Georgiev, Softel Labs
4
+ #
5
+ # This is a proprietary file and may not be copied,
6
+ # distributed, or modified without express permission
7
+ # from the owner. For licensing inquiries, please
8
+ # contact pavlin@softel.bg.
9
+ #
10
+ # 2024
11
+ #
12
+
13
+ import os
14
+ import argparse
15
+
16
+ from sciveo.common.tools.logger import *
17
+ from sciveo.common.tools.timers import Timer
18
+ from sciveo.monitoring.start import MonitorStart
19
+ from sciveo.monitoring.network import NetworkTools
20
+ from sciveo.common.tools.configuration import GlobalConfiguration
21
+
22
+
23
+ def main():
24
+ config = GlobalConfiguration.get()
25
+
26
+ parser = argparse.ArgumentParser(description='sciveo CLI')
27
+ parser.add_argument('command', choices=['init', 'monitor', 'scan'], help='Command to execute')
28
+ parser.add_argument('--period', type=int, default=120, help='Period in seconds')
29
+ parser.add_argument('--block', type=bool, default=True, help='Block flag')
30
+ parser.add_argument('--auth', type=str, default=config['secret_access_key'], help='Auth secret access key')
31
+ parser.add_argument('--timeout', type=float, default=0.5, help='Timeout')
32
+ parser.add_argument('--port', type=int, default=22, help='Host port number, used for network ops')
33
+ parser.add_argument('--localhost', type=bool, default=False, help='Add localhost to list of hosts')
34
+ args = parser.parse_args()
35
+
36
+ if args.command == 'monitor':
37
+ MonitorStart(period=args.period, block=args.block)()
38
+ elif args.command == 'scan':
39
+ NetworkTools(timeout=args.timeout, localhost=args.localhost).scan_port(port=args.port)
40
+ elif args.command == 'init':
41
+ home = os.path.expanduser('~')
42
+ base_path = os.path.join(home, '.sciveo')
43
+ if not os.path.exists(base_path):
44
+ os.makedirs(base_path)
45
+ default_lines = [
46
+ "secret_access_key=<your secret access key>",
47
+ "api_base_url=https://sciveo.com",
48
+ "log_min_level=DEBUG"
49
+ ]
50
+ with open("default", 'w') as fp:
51
+ for line in default_lines:
52
+ fp.write(line + '\n')
53
+ else:
54
+ info(f"init, [{base_path}] already there")
55
+ else:
56
+ warning(args.command, "not implemented")
57
+
58
+ if __name__ == '__main__':
59
+ main()
@@ -0,0 +1,95 @@
1
+ #
2
+ # Pavlin Georgiev, Softel Labs
3
+ #
4
+ # This is a proprietary file and may not be copied,
5
+ # distributed, or modified without express permission
6
+ # from the owner. For licensing inquiries, please
7
+ # contact pavlin@softel.bg.
8
+ #
9
+ # 2024
10
+ #
11
+
12
+ import socket
13
+ import threading
14
+
15
+ from sciveo.common.tools.logger import *
16
+ from sciveo.common.tools.timers import Timer
17
+
18
+
19
+ class NetworkTools:
20
+ def __init__(self, **kwargs):
21
+ self.default_arguments = {
22
+ "timeout": 0.1,
23
+ "localhost": False,
24
+ }
25
+
26
+ self.arguments = {}
27
+ for k, v in self.default_arguments.items():
28
+ self.arguments[k] = kwargs.get(k, v)
29
+
30
+ self.net_classes = ["192.168.", "10."]
31
+ for i in range(16, 32):
32
+ self.net_classes.append(f"172.{i}.")
33
+
34
+ self.data = {"scan": {}}
35
+ self.data_lock = threading.Lock()
36
+
37
+ def get_local_nets(self):
38
+ list_local_ips = []
39
+ try:
40
+ import netifaces
41
+ interfaces = netifaces.interfaces()
42
+ for interface in interfaces:
43
+ addrs = netifaces.ifaddresses(interface)
44
+ if netifaces.AF_INET in addrs:
45
+ ip = addrs[netifaces.AF_INET][0]['addr']
46
+ for net_class in self.net_classes:
47
+ if ip.startswith(net_class):
48
+ list_local_ips.append(ip)
49
+ except Exception as e:
50
+ warning(type(self).__name__, "netifaces not installed")
51
+ return list_local_ips
52
+
53
+ def generate_ip_list(self, base_ip):
54
+ octets = base_ip.split('.')
55
+ network_prefix = '.'.join(octets[:3])
56
+ return [f'{network_prefix}.{i}' for i in range(1, 255)]
57
+
58
+ def scan_port(self, port=22):
59
+ t = Timer()
60
+ list_local_ips = self.get_local_nets()
61
+ # debug(type(self).__name__, "scan_port", "list_local_ips", list_local_ips)
62
+ self.data["scan"].setdefault(port, [])
63
+ for local_ip in list_local_ips:
64
+ list_ip = self.generate_ip_list(local_ip)
65
+ self.scan_port_hosts(list_ip, port)
66
+ if self.arguments["localhost"]:
67
+ self.scan_port_hosts(["127.0.0.1"], port)
68
+ debug(type(self).__name__, f"scan_port [{port}] elapsed time {t.stop():.1f}s", self.data["scan"][port])
69
+ return self.data["scan"][port]
70
+
71
+ def scan_port_hosts(self, list_ip, port=22):
72
+ timeout = self.arguments["timeout"]
73
+ list_threads = []
74
+ for ip in list_ip:
75
+ t = threading.Thread(target=self.scan_host_port, args=(ip, port, timeout))
76
+ t.start()
77
+ list_threads.append(t)
78
+ for t in list_threads:
79
+ t.join()
80
+
81
+ def scan_host_port(self, ip, port, timeout):
82
+ try:
83
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
84
+ sock.settimeout(timeout)
85
+ result = sock.connect_ex((ip, port))
86
+ if result == 0:
87
+ with self.data_lock:
88
+ self.data["scan"][port].append(ip)
89
+ # debug(type(self).__name__, "scan_ports", ip, port, result)
90
+ except socket.error:
91
+ pass
92
+
93
+
94
+ if __name__ == "__main__":
95
+ print(NetworkTools(timeout=0.5, localhost=False).scan_port(port=9901))
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.1.10'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.8
3
+ Version: 0.1.10
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env python
2
- #
3
- # Pavlin Georgiev, Softel Labs
4
- #
5
- # This is a proprietary file and may not be copied,
6
- # distributed, or modified without express permission
7
- # from the owner. For licensing inquiries, please
8
- # contact pavlin@softel.bg.
9
- #
10
- # 2024
11
- #
12
-
13
- import os
14
- import argparse
15
-
16
- from sciveo.common.tools.logger import *
17
- from sciveo.monitoring.start import MonitorStart
18
- from sciveo.common.tools.configuration import GlobalConfiguration
19
-
20
-
21
- def main():
22
- config = GlobalConfiguration.get()
23
-
24
- parser = argparse.ArgumentParser(description='sciveo CLI')
25
- parser.add_argument('command', choices=['monitor', 'net'], help='Command to execute')
26
- parser.add_argument('--period', type=int, default=120, help='Period in seconds')
27
- parser.add_argument('--block', type=bool, default=True, help='Block flag')
28
- parser.add_argument('--auth', type=str, default=config['secret_access_key'], help='Auth secret access key')
29
- args = parser.parse_args()
30
-
31
- if args.command == 'monitor':
32
- MonitorStart(period=args.period, block=args.block)()
33
- elif args.command == 'net':
34
- warning(args.command, "not implemented")
35
- else:
36
- warning(args.command, "not implemented")
37
-
38
- if __name__ == '__main__':
39
- main()
@@ -1,130 +0,0 @@
1
- #
2
- # Pavlin Georgiev, Softel Labs
3
- #
4
- # This is a proprietary file and may not be copied,
5
- # distributed, or modified without express permission
6
- # from the owner. For licensing inquiries, please
7
- # contact pavlin@softel.bg.
8
- #
9
- # 2024
10
- #
11
-
12
- import socket
13
- import asyncio
14
-
15
- from sciveo.common.tools.logger import *
16
- from sciveo.common.tools.timers import Timer
17
-
18
-
19
- class NetworkScanner:
20
- def __init__(self, timeout=1.0):
21
- self.timeout = timeout
22
-
23
- async def scan_port(self, ip, port):
24
- try:
25
- reader, writer = await asyncio.wait_for(asyncio.open_connection(ip, port), timeout=self.timeout)
26
- writer.close()
27
- await writer.wait_closed()
28
- return (ip, port)
29
- except Exception as e:
30
- # print("Exception", e)
31
- return None
32
-
33
- async def scan_all_ports(self, ip, ports):
34
- tasks = [self.scan_port(ip, port) for port in ports]
35
- return await asyncio.gather(*tasks)
36
-
37
- async def scan_async(self, ips, ports):
38
- results = []
39
- for ip in ips:
40
- results.extend(await self.scan_all_ports(ip, ports))
41
- results = [x for x in results if x is not None]
42
- return results
43
-
44
- def scan(self, ips, ports):
45
- return asyncio.run(self.scan_async(ips, ports))
46
-
47
-
48
- class NetworkTools:
49
- def __init__(self, **kwargs):
50
- self.default_arguments = {
51
- "timeout": 0.1,
52
- "localhost": False,
53
- }
54
-
55
- self.arguments = {}
56
- for k, v in self.default_arguments.items():
57
- self.arguments[k] = kwargs.get(k, v)
58
-
59
- self.net_classes = ["192.168.", "10."]
60
- for i in range(16, 32):
61
- self.net_classes.append(f"172.{i}.")
62
-
63
- def get_local_nets(self):
64
- list_local_ips = []
65
- try:
66
- import netifaces
67
- interfaces = netifaces.interfaces()
68
- for interface in interfaces:
69
- addrs = netifaces.ifaddresses(interface)
70
- if netifaces.AF_INET in addrs:
71
- ip = addrs[netifaces.AF_INET][0]['addr']
72
- for net_class in self.net_classes:
73
- if ip.startswith(net_class):
74
- list_local_ips.append(ip)
75
- except Exception as e:
76
- warning(type(self).__name__, "netifaces not installed")
77
- return list_local_ips
78
-
79
- def generate_ip_list(self, base_ip):
80
- octets = base_ip.split('.')
81
- network_prefix = '.'.join(octets[:3])
82
- return [f'{network_prefix}.{i}' for i in range(1, 255)]
83
-
84
- def scan_port(self, port=22):
85
- t = Timer()
86
- result = []
87
- list_local_ips = self.get_local_nets()
88
- debug(type(self).__name__, "scan_port", "list_local_ips", list_local_ips)
89
- for local_ip in list_local_ips:
90
- list_ip = self.generate_ip_list(local_ip)
91
- result += self.scan_port_hosts(list_ip, port)
92
- if self.arguments["localhost"]:
93
- result += self.scan_port_hosts(["127.0.0.1"], port)
94
- debug(type(self).__name__, "scan_port elapsed time", t.stop(), "result", result)
95
- return result
96
-
97
- def scan_port_hosts(self, list_ip, port=22):
98
- list_hosts = []
99
- timeout = self.arguments["timeout"]
100
- for ip in list_ip:
101
- try:
102
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
103
- sock.settimeout(timeout)
104
- result = sock.connect_ex((ip, port))
105
- if result == 0:
106
- list_hosts.append(ip)
107
- # debug(type(self).__name__, "scan_ports", ip, port, result)
108
- except socket.error:
109
- pass
110
- return list_hosts
111
-
112
-
113
- if __name__ == "__main__":
114
- t1 = Timer()
115
- net = NetworkTools(timeout=0.5, localhost=True)
116
- result = net.scan_port(port=22)
117
- t1 = t1.stop()
118
- print(result, "elapsed", t1)
119
-
120
- t2 = Timer()
121
- list_local_ips = net.get_local_nets()
122
- list_scan_ips = []
123
- for local_ip in list_local_ips:
124
- list_scan_ips += net.generate_ip_list(local_ip)
125
- # print(list_scan_ips)
126
- ns = NetworkScanner(timeout=0.5)
127
- result = ns.scan(list_scan_ips, [22])
128
- t2 = t2.stop()
129
- print(result, "elapsed", t2)
130
- print("elapsed", t1, t2, t1 - t2)
@@ -1,2 +0,0 @@
1
-
2
- __version__ = '0.1.8'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes