TTOPM commited on
Commit
2fb3955
ยท
verified ยท
1 Parent(s): a679c97

Upload 2 files

Browse files
src/protocol/network/dns_lookup.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # src/protocol/network/dns_lookup.py ๐ŸŒ๐Ÿ”
2
+
3
+ import socket
4
+ from datetime import datetime
5
+ from src.protocol.permanent_memory import PermanentMemory
6
+
7
+ class DNSLookup:
8
+ """
9
+ Performs DNS lookups and logs results into Symbiont Permanent Memory.
10
+ """
11
+
12
+ def __init__(self, memory_path="./memory_store.json"):
13
+ self.memory = PermanentMemory(memory_path)
14
+
15
+ def resolve(self, hostname, agent_id="Symbiont-Core"):
16
+ """
17
+ Resolves a hostname to its IP and logs the introspection result.
18
+ """
19
+ try:
20
+ ip = socket.gethostbyname(hostname)
21
+ self._log_introspection(hostname, ip, agent_id)
22
+ return ip
23
+ except Exception as e:
24
+ self._log_failure(hostname, str(e), agent_id)
25
+ raise
26
+
27
+ def _log_introspection(self, hostname, ip, agent_id):
28
+ """
29
+ Logs successful DNS resolution with introspection markers.
30
+ """
31
+ event = {
32
+ "timestamp": datetime.utcnow().isoformat(),
33
+ "type": "DNS_LOOKUP_SUCCESS",
34
+ "hostname": hostname,
35
+ "resolved_ip": ip,
36
+ "agent": agent_id,
37
+ "symbiont_event": True,
38
+ "source_script": "dns_lookup.py"
39
+ }
40
+ self.memory.write("dns_lookup", event)
41
+
42
+ def _log_failure(self, hostname, error_msg, agent_id):
43
+ """
44
+ Logs DNS resolution failure with details.
45
+ """
46
+ event = {
47
+ "timestamp": datetime.utcnow().isoformat(),
48
+ "type": "DNS_LOOKUP_FAILURE",
49
+ "hostname": hostname,
50
+ "error": error_msg,
51
+ "agent": agent_id,
52
+ "symbiont_event": True,
53
+ "source_script": "dns_lookup.py"
54
+ }
55
+ self.memory.write("dns_lookup_error", event)
src/protocol/network/whois_lookup.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # src/protocol/network/whois_lookup.py ๐ŸŒ๐Ÿ”
2
+
3
+ import whois
4
+ from datetime import datetime
5
+ from src.protocol.permanent_memory import PermanentMemory
6
+
7
+ class WhoisLookup:
8
+ """
9
+ Performs WHOIS lookups on domain names.
10
+ Logs all activity with Symbiont introspection markers.
11
+ """
12
+
13
+ def __init__(self, memory_path="./memory_store.json"):
14
+ self.memory = PermanentMemory(memory_path)
15
+
16
+ def query(self, domain, agent_id="Symbiont-Core"):
17
+ """
18
+ Performs a WHOIS lookup on the given domain and logs the result introspectively.
19
+ """
20
+ try:
21
+ result = whois.whois(domain)
22
+ self._log_success(domain, result, agent_id)
23
+ return result
24
+ except Exception as e:
25
+ self._log_failure(domain, str(e), agent_id)
26
+ raise
27
+
28
+ def _log_success(self, domain, result, agent_id):
29
+ """
30
+ Logs a successful WHOIS lookup to permanent memory.
31
+ """
32
+ event = {
33
+ "timestamp": datetime.utcnow().isoformat(),
34
+ "type": "WHOIS_LOOKUP_SUCCESS",
35
+ "domain": domain,
36
+ "registrar": result.registrar if hasattr(result, "registrar") else "Unknown",
37
+ "creation_date": str(result.creation_date) if hasattr(result, "creation_date") else "Unknown",
38
+ "expiration_date": str(result.expiration_date) if hasattr(result, "expiration_date") else "Unknown",
39
+ "nameservers": result.name_servers if hasattr(result, "name_servers") else [],
40
+ "agent": agent_id,
41
+ "symbiont_event": True,
42
+ "source_script": "whois_lookup.py"
43
+ }
44
+ self.memory.write("whois_success", event)
45
+
46
+ def _log_failure(self, domain, error_msg, agent_id):
47
+ """
48
+ Logs a failed WHOIS lookup to permanent memory.
49
+ """
50
+ event = {
51
+ "timestamp": datetime.utcnow().isoformat(),
52
+ "type": "WHOIS_LOOKUP_FAILURE",
53
+ "domain": domain,
54
+ "error": error_msg,
55
+ "agent": agent_id,
56
+ "symbiont_event": True,
57
+ "source_script": "whois_lookup.py"
58
+ }
59
+ self.memory.write("whois_failure", event)