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

Function scan_host_background

webapp_modern.py:8915–9032  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8913 if network_data:
8914 logger.debug("Used netkb data as fallback.")
8915 else:
8916 network_data = []
8917
8918 current_ssid = get_current_wifi_ssid()
8919 logger.info(f"Returning {len(network_data)} network entries for WiFi: {current_ssid}")
8920 return network_data
8921
8922
8923@app.route('/api/network/stable')
8924def get_stable_network_data():
8925 """Get stable, aggregated network data for the Network tab from SQLite database"""
8926 with _network_context_from_request():
8927 try:
8928 db = get_db(currentdir=shared_data.currentdir)
8929
8930 # Get all hosts from SQLite database
8931 hosts = db.get_all_hosts()
8932
8933 # Also get any recent ARP scan cache data for real-time enrichment
8934 recent_arp_data = network_scan_cache.get('arp_hosts', {})
8935
8936 logger.info(f"Loaded {len(hosts)} entries from SQLite database for stable API")
8937
8938 # Merge and enrich the data
8939 enriched_hosts = []
8940 processed_ips = set()
8941
8942 # Process SQLite hosts
8943 for host in hosts:
8944 ip = host.get('ip', '').strip()
8945 # Skip if empty, already processed, or is STANDALONE
8946 if not ip or ip in processed_ips or ip == 'STANDALONE':
8947 continue
8948
8949 processed_ips.add(ip)
8950
8951 # Parse ports from semicolon-separated string to list
8952 ports_str = host.get('ports', '')
8953 if ports_str:
8954 ports = [p.strip() for p in ports_str.split(';') if p.strip()]
8955 else:
8956 ports = []
8957
8958 # Determine status based on SQLite status field
8959 status = host.get('status', 'unknown')
8960 if status == 'alive':
8961 host_status = 'up'
8962 elif status == 'degraded':
8963 host_status = 'degraded'
8964 else:
8965 host_status = 'unknown'
8966
8967 host_data = {
8968 'ip': ip,
8969 'hostname': _normalize_value(host.get('hostname'), 'Unknown'),
8970 'mac': _normalize_value(host.get('mac'), 'Unknown'),
8971 'status': host_status,
8972 'ports': ';'.join(ports) if ports else 'Unknown',

Callers

nothing calls this directly

Calls 11

run_targeted_arp_scanFunction · 0.85
resolve_ip_hostnameFunction · 0.85
update_netkb_entryFunction · 0.85
run_nmap_fallbackFunction · 0.85
infoMethod · 0.80
emitMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
runMethod · 0.45
updateMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected