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

Function start_realtime_scan

webapp_modern.py:8818–8873  ·  view source on GitHub ↗

Start real-time vulnerability scanning

()

Source from the content-addressed store, hash-verified

8816 ['systemd-run', '--no-block', '--collect',
8817 '--unit=ragnar-to-pwnagotchi-swap',
8818 'bash', '-c',
8819 'systemctl stop ragnar.service && {'
8820 ' python3 -OO /home/ragnar/Ragnar/wipe_epd.py 2>/dev/null || true;'
8821 ' systemctl start bettercap.service || true;'
8822 ' systemctl start pwnagotchi.service || true;'
8823 ' systemctl start ragnar-swap-button.service || true;'
8824 ' }'],
8825 stdout=subprocess.DEVNULL,
8826 stderr=subprocess.DEVNULL,
8827 )
8828 logger.info("Scheduled systemd-run swap: stop ragnar → start pwnagotchi")
8829 except Exception as exc:
8830 logger.error(f"Failed to schedule pwnagotchi start sequence: {exc}")
8831 return
8832 else:
8833 success, detail = _start_service_with_monitor('ragnar.service')
8834 if success:
8835 logger.info("Ragnar service reported active; stopping Pwnagotchi and bettercap services")
8836 _stop_service('pwnagotchi.service')
8837 _stop_service('bettercap.service')
8838 message = 'Ragnar service is running'
8839 _write_pwn_status_file('running', message, 'swap', {'target_mode': 'ragnar'})
8840 _update_pwn_config({'pwnagotchi_mode': 'ragnar', 'pwnagotchi_last_status': message})
8841 else:
8842 logger.error(f"Ragnar service failed to start: {detail}")
8843 failure_message = _format_service_failure_message('ragnar.service')
8844 extra = {'target_mode': 'pwnagotchi'}
8845 if detail:
8846 extra['service_error_detail'] = detail
8847 _write_pwn_status_file('error', failure_message, 'error', extra)
8848 _update_pwn_config({'pwnagotchi_mode': 'pwnagotchi', 'pwnagotchi_last_status': failure_message})
8849 _start_service_with_monitor('pwnagotchi.service', timeout=30)
8850
8851 _emit_pwn_status_update()
8852
8853def resolve_ip_hostname(ip):
8854 try:
8855 if _is_valid_ipv4(ip):
8856 hostname, _, _ = socket.gethostbyaddr(ip)
8857 return hostname
8858 except (socket.herror, socket.gaierror):
8859 return ''
8860 except Exception as e:
8861 logger.debug(f"Hostname resolution failed for {ip}: {e}")
8862 return ''
8863
8864
8865def update_vulnerability_output(ip, hostname, mac, is_alive):
8866 """Create or update vulnerability scan results file for discovered host"""
8867 try:
8868 # Ensure vulnerabilities output directory exists
8869 vuln_output_dir = os.path.join('data', 'output', 'vulnerabilities')
8870 os.makedirs(vuln_output_dir, exist_ok=True)
8871
8872 # Create or update vulnerability scan results file for this IP
8873 vuln_file = os.path.join(vuln_output_dir, f'scan_{ip.replace(".", "_")}.txt')
8874
8875 with open(vuln_file, 'w') as f:

Callers

nothing calls this directly

Calls 3

errorMethod · 0.80
getMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected