sciveo 0.1.8__tar.gz → 0.1.9__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 (43) hide show
  1. {sciveo-0.1.8 → sciveo-0.1.9}/PKG-INFO +1 -1
  2. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/monitoring/network.py +29 -62
  3. sciveo-0.1.9/sciveo/version.py +2 -0
  4. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo.egg-info/PKG-INFO +1 -1
  5. sciveo-0.1.8/sciveo/version.py +0 -2
  6. {sciveo-0.1.8 → sciveo-0.1.9}/README.md +0 -0
  7. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/__init__.py +0 -0
  8. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/api/__init__.py +0 -0
  9. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/api/base.py +0 -0
  10. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/api/upload.py +0 -0
  11. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/cli.py +0 -0
  12. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/__init__.py +0 -0
  13. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/configuration.py +0 -0
  14. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/model.py +0 -0
  15. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/optimizers.py +0 -0
  16. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/sampling.py +0 -0
  17. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/__init__.py +0 -0
  18. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/configuration.py +0 -0
  19. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/daemon.py +0 -0
  20. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/formating.py +0 -0
  21. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/hardware.py +0 -0
  22. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/logger.py +0 -0
  23. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/synchronized.py +0 -0
  24. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/common/tools/timers.py +0 -0
  25. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/content/__init__.py +0 -0
  26. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/content/dataset.py +0 -0
  27. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/content/experiment.py +0 -0
  28. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/content/project.py +0 -0
  29. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/content/runner.py +0 -0
  30. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/monitoring/__init__.py +0 -0
  31. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/monitoring/monitor.py +0 -0
  32. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo/monitoring/start.py +0 -0
  33. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo.egg-info/SOURCES.txt +0 -0
  34. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo.egg-info/dependency_links.txt +0 -0
  35. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo.egg-info/entry_points.txt +0 -0
  36. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo.egg-info/requires.txt +0 -0
  37. {sciveo-0.1.8 → sciveo-0.1.9}/sciveo.egg-info/top_level.txt +0 -0
  38. {sciveo-0.1.8 → sciveo-0.1.9}/setup.cfg +0 -0
  39. {sciveo-0.1.8 → sciveo-0.1.9}/setup.py +0 -0
  40. {sciveo-0.1.8 → sciveo-0.1.9}/test/test_configuration.py +0 -0
  41. {sciveo-0.1.8 → sciveo-0.1.9}/test/test_monitoring.py +0 -0
  42. {sciveo-0.1.8 → sciveo-0.1.9}/test/test_runner.py +0 -0
  43. {sciveo-0.1.8 → sciveo-0.1.9}/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.9
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -10,41 +10,12 @@
10
10
  #
11
11
 
12
12
  import socket
13
- import asyncio
13
+ import threading
14
14
 
15
15
  from sciveo.common.tools.logger import *
16
16
  from sciveo.common.tools.timers import Timer
17
17
 
18
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
19
  class NetworkTools:
49
20
  def __init__(self, **kwargs):
50
21
  self.default_arguments = {
@@ -60,6 +31,9 @@ class NetworkTools:
60
31
  for i in range(16, 32):
61
32
  self.net_classes.append(f"172.{i}.")
62
33
 
34
+ self.data = {"scan": {}}
35
+ self.data_lock = threading.Lock()
36
+
63
37
  def get_local_nets(self):
64
38
  list_local_ips = []
65
39
  try:
@@ -83,48 +57,41 @@ class NetworkTools:
83
57
 
84
58
  def scan_port(self, port=22):
85
59
  t = Timer()
86
- result = []
87
60
  list_local_ips = self.get_local_nets()
88
61
  debug(type(self).__name__, "scan_port", "list_local_ips", list_local_ips)
89
62
  for local_ip in list_local_ips:
90
63
  list_ip = self.generate_ip_list(local_ip)
91
- result += self.scan_port_hosts(list_ip, port)
64
+ self.scan_port_hosts(list_ip, port)
92
65
  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
66
+ self.scan_port_hosts(["127.0.0.1"], port)
67
+ debug(type(self).__name__, f"scan_port [{port}] elapsed time", t.stop(), self.data["scan"][port])
68
+ return self.data["scan"][port]
96
69
 
97
70
  def scan_port_hosts(self, list_ip, port=22):
98
- list_hosts = []
99
71
  timeout = self.arguments["timeout"]
72
+ list_threads = []
100
73
  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
74
+ t = threading.Thread(target=self.scan_host_port, args=(ip, port, timeout))
75
+ t.start()
76
+ list_threads.append(t)
77
+ for t in list_threads:
78
+ t.join()
79
+
80
+ def scan_host_port(self, ip, port, timeout):
81
+ try:
82
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
83
+ sock.settimeout(timeout)
84
+ result = sock.connect_ex((ip, port))
85
+ if result == 0:
86
+ with self.data_lock:
87
+ self.data["scan"].setdefault(port, [])
88
+ self.data["scan"][port].append(ip)
89
+ # debug(type(self).__name__, "scan_ports", ip, port, result)
90
+ except socket.error:
91
+ pass
111
92
 
112
93
 
113
94
  if __name__ == "__main__":
114
- t1 = Timer()
115
95
  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)
96
+ list_hosts = net.scan_port(port=22)
97
+ print(list_hosts)
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.1.9'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciveo
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Description-Content-Type: text/markdown
5
5
  Provides-Extra: mon
6
6
  Provides-Extra: net
@@ -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
File without changes
File without changes
File without changes
File without changes
File without changes