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

Method start

actions/scanning.py:1068–1181  ·  view source on GitHub ↗

Starts the port scanning process using nmap for reliable scanning.

(self)

Source from the content-addressed store, hash-verified

1066 self.extra_ports = extra_ports
1067
1068 def start(self):
1069 """
1070 Starts the port scanning process using nmap for reliable scanning.
1071 """
1072 scan_start_time = time.time()
1073 try:
1074 # Build port list to scan
1075 ports_to_scan = list(range(self.portstart, self.portend))
1076 extra_ports = self.extra_ports or []
1077 ports_to_scan.extend(extra_ports)
1078
1079 # Remove duplicates while preserving order
1080 seen_ports = set()
1081 ordered_ports = []
1082 for port in ports_to_scan:
1083 if port in seen_ports:
1084 continue
1085 seen_ports.add(port)
1086 ordered_ports.append(port)
1087
1088 self.logger.info(f"🎯 PORT SCAN STARTING: {self.target} - {len(ordered_ports)} ports (range: {self.portstart}-{self.portend}, extra: {len(extra_ports)} ports)")
1089 self.logger.debug(f"Port list preview for {self.target}: {sorted(ordered_ports)[:10]}{'...' if len(ordered_ports) > 10 else ''}")
1090
1091 # Use nmap for more reliable port scanning
1092 port_list = ','.join(map(str, ordered_ports))
1093
1094 # Nmap arguments: -Pn (skip ping), -sT (TCP connect), --host-timeout (per-host timeout)
1095 # Removed --open flag to see all port states (open, closed, filtered)
1096 nmap_args = f"-Pn -sT -p{port_list} --host-timeout 30s"
1097
1098 self.logger.debug(f"🔍 Executing nmap command for {self.target}: nmap {nmap_args} {self.target}")
1099
1100 try:
1101 nmap_start_time = time.time()
1102 # Use the nmap scanner from the outer instance
1103 self.outer_instance.nm.scan(self.target, arguments=nmap_args)
1104 nmap_duration = time.time() - nmap_start_time
1105
1106 self.logger.debug(f"⏱️ Nmap scan completed for {self.target} in {nmap_duration:.2f}s")
1107
1108 # Log detailed nmap results
1109 all_hosts = self.outer_instance.nm.all_hosts()
1110 self.logger.debug(f"📊 Nmap results for {self.target}: all_hosts={all_hosts}")
1111
1112 if self.target in all_hosts:
1113 host_data = self.outer_instance.nm[self.target]
1114 self.logger.debug(f"📋 Host data keys for {self.target}: {list(host_data.keys())}")
1115
1116 # Log scan info if available
1117 if 'status' in host_data:
1118 self.logger.debug(f"🔄 Host status for {self.target}: {host_data['status']}")
1119
1120 # Check TCP ports
1121 if 'tcp' in host_data:
1122 tcp_ports = host_data['tcp']
1123 self.logger.info(f"🔌 TCP scan results for {self.target}: {len(tcp_ports)} ports scanned")
1124 open_count = 0
1125 closed_count = 0

Callers

nothing calls this directly

Calls 14

_socket_scan_fallbackMethod · 0.95
rangeFunction · 0.85
extendMethod · 0.80
addMethod · 0.80
appendMethod · 0.80
infoMethod · 0.80
debugMethod · 0.80
all_hostsMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
setFunction · 0.50
scanMethod · 0.45

Tested by

no test coverage detected