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

Method deep_scan_host

actions/scanning.py:1825–2036  ·  view source on GitHub ↗
(self, ip, portstart=1, portend=65535, progress_callback=None, use_top_ports=True)

Source from the content-addressed store, hash-verified

1823 self._active_scan_network = previous_network_hint
1824
1825 def deep_scan_host(self, ip, portstart=1, portend=65535, progress_callback=None, use_top_ports=True):
1826 # Debug input parameters (single consolidated line for easier grepping)
1827 self.logger.info("🔍 DEEP SCAN METHOD CALLED")
1828 self.logger.info(
1829 f"🎯 DEEP SCAN PARAMETERS ip={ip} portstart={portstart} portend={portend} use_top_ports={use_top_ports}"
1830 )
1831 self.logger.debug(f" progress_callback={progress_callback}")
1832
1833 if not ip:
1834 self.logger.error("❌ CRITICAL ERROR: IP parameter is empty/None!")
1835 return {
1836 'success': False,
1837 'open_ports': [],
1838 'hostname': '',
1839 'message': 'IP address is required but was empty'
1840 }
1841
1842 scan_mode = 'top3000' if use_top_ports else 'full-range'
1843 self.logger.info(f"🔍 DEEP SCAN INIT ip={ip} mode={scan_mode} range={portstart}-{portend}")
1844
1845 # Quick connectivity test (best-effort)
1846 self.logger.info(f"📡 Testing connectivity to {ip}...")
1847 try:
1848 ping_result = subprocess.run(['ping', '-c', '1', '-W', '2', ip],
1849 capture_output=True, text=True, timeout=5)
1850 if ping_result.returncode == 0:
1851 self.logger.info(f"✅ Ping successful to {ip} - host is reachable")
1852 else:
1853 self.logger.warning(f"⚠️ Ping failed to {ip} - host may be down or firewalled")
1854 except Exception as ping_error:
1855 self.logger.warning(f"⚠️ Ping test failed: {ping_error}")
1856
1857 try:
1858 # ===== STAGE 1: PORT DISCOVERY SCAN =====
1859 self.logger.info(f"📡 STAGE 1: Port discovery scan starting...")
1860
1861 # Build nmap args depending on mode, honoring the scan_intensity profile
1862 profile = get_scan_profile(self.shared_data)
1863 if use_top_ports:
1864 nmap_args = (
1865 f"-Pn -sT --top-ports {profile['top_ports']} --open "
1866 f"{profile['timing']} --min-rate {max(50, profile['min_rate'] // 2)} "
1867 f"--max-retries 1 -v"
1868 )
1869 self.logger.info(f"🚀 Port scan mode: TOP {profile['top_ports']} common ports (profile: {profile['label']})")
1870 self.logger.info(f" Command: nmap {nmap_args} {ip}")
1871 else:
1872 nmap_args = (
1873 f"-Pn -sT -p{portstart}-{portend} --open "
1874 f"{profile['timing']} --min-rate {profile['min_rate']} "
1875 f"--max-retries 1 -v"
1876 )
1877 total_ports = portend - portstart + 1
1878 self.logger.info(f"🚀 Port scan mode: FULL RANGE ({total_ports} ports, profile: {profile['label']})")
1879 self.logger.info(f" Command: nmap {nmap_args} {ip}")
1880
1881 # Notify scan started
1882 if progress_callback:

Callers 1

deep_scan_backgroundFunction · 0.95

Calls 14

get_scan_profileFunction · 0.85
progress_callbackFunction · 0.85
infoMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
warningMethod · 0.80
all_hostsMethod · 0.80
hostnameMethod · 0.80
appendMethod · 0.80
runMethod · 0.45
scanMethod · 0.45

Tested by

no test coverage detected