MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / serve_netkb_data_json

Method serve_netkb_data_json

utils.py:87–110  ·  view source on GitHub ↗
(self, handler)

Source from the content-addressed store, hash-verified

85 self.logger.error(f"Module {module_name} is missing required attributes: {e}")
86
87 def serve_netkb_data_json(self, handler):
88 try:
89 netkb_file = self.shared_data.netkbfile
90 with open(netkb_file, 'r', encoding='utf-8') as file:
91 reader = csv.DictReader(file)
92 data = [row for row in reader if row.get('Alive') == '1']
93
94 fieldnames = reader.fieldnames or []
95 actions = fieldnames[5:] if len(fieldnames) > 5 else [] # Actions are columns after 'Ports'
96 response_data = {
97 'ips': [row['IPs'] for row in data],
98 'ports': {row['IPs']: row['Ports'].split(';') for row in data},
99 'actions': actions
100 }
101
102 handler.send_response(200)
103 handler.send_header("Content-type", "application/json")
104 handler.end_headers()
105 handler.wfile.write(json.dumps(response_data).encode('utf-8'))
106 except Exception as e:
107 handler.send_response(500)
108 handler.send_header("Content-type", "application/json")
109 handler.end_headers()
110 handler.wfile.write(json.dumps({"status": "error", "message": str(e)}).encode('utf-8'))
111
112 def execute_manual_attack(self, handler):
113 try:

Callers

nothing calls this directly

Calls 3

getMethod · 0.45
writeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected