File size: 2,164 Bytes
2fb3955 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # src/protocol/network/whois_lookup.py 🌐🔍
import whois
from datetime import datetime
from src.protocol.permanent_memory import PermanentMemory
class WhoisLookup:
"""
Performs WHOIS lookups on domain names.
Logs all activity with Symbiont introspection markers.
"""
def __init__(self, memory_path="./memory_store.json"):
self.memory = PermanentMemory(memory_path)
def query(self, domain, agent_id="Symbiont-Core"):
"""
Performs a WHOIS lookup on the given domain and logs the result introspectively.
"""
try:
result = whois.whois(domain)
self._log_success(domain, result, agent_id)
return result
except Exception as e:
self._log_failure(domain, str(e), agent_id)
raise
def _log_success(self, domain, result, agent_id):
"""
Logs a successful WHOIS lookup to permanent memory.
"""
event = {
"timestamp": datetime.utcnow().isoformat(),
"type": "WHOIS_LOOKUP_SUCCESS",
"domain": domain,
"registrar": result.registrar if hasattr(result, "registrar") else "Unknown",
"creation_date": str(result.creation_date) if hasattr(result, "creation_date") else "Unknown",
"expiration_date": str(result.expiration_date) if hasattr(result, "expiration_date") else "Unknown",
"nameservers": result.name_servers if hasattr(result, "name_servers") else [],
"agent": agent_id,
"symbiont_event": True,
"source_script": "whois_lookup.py"
}
self.memory.write("whois_success", event)
def _log_failure(self, domain, error_msg, agent_id):
"""
Logs a failed WHOIS lookup to permanent memory.
"""
event = {
"timestamp": datetime.utcnow().isoformat(),
"type": "WHOIS_LOOKUP_FAILURE",
"domain": domain,
"error": error_msg,
"agent": agent_id,
"symbiont_event": True,
"source_script": "whois_lookup.py"
}
self.memory.write("whois_failure", event)
|