Main function to scan network
(interface='eth0', port_range='1-1000', quick=False)
| 112 | return {'hostname': 'Error', 'ports': []} |
| 113 | |
| 114 | def scan_network(interface='eth0', port_range='1-1000', quick=False): |
| 115 | """Main function to scan network""" |
| 116 | |
| 117 | # Check if running as root |
| 118 | if subprocess.run(['id', '-u'], capture_output=True, text=True).stdout.strip() != '0': |
| 119 | print("Warning: This script should be run with sudo for best results") |
| 120 | |
| 121 | check_requirements() |
| 122 | |
| 123 | # Run ARP scan |
| 124 | devices = run_arp_scan(interface) |
| 125 | |
| 126 | if not devices: |
| 127 | print("No devices found. Check your interface name.") |
| 128 | print("Common interfaces: eth0, wlan0, enp0s3") |
| 129 | return [] |
| 130 | |
| 131 | # Scan each device with Nmap |
| 132 | results = [] |
| 133 | for i, device in enumerate(devices, 1): |
| 134 | print(f"\n[*] Scanning device {i}/{len(devices)}: {device['ip']}") |
| 135 | |
| 136 | if quick: |
| 137 | # Quick scan - just get hostname |
| 138 | nmap_data = run_nmap_scan(device['ip'], '80,443,22') |
| 139 | else: |
| 140 | # Full scan |
| 141 | nmap_data = run_nmap_scan(device['ip'], port_range) |
| 142 | |
| 143 | results.append({ |
| 144 | 'ip': device['ip'], |
| 145 | 'mac': device['mac'], |
| 146 | 'vendor': device['vendor'], |
| 147 | 'hostname': nmap_data['hostname'], |
| 148 | 'open_ports': nmap_data['ports'] |
| 149 | }) |
| 150 | |
| 151 | return results |
| 152 | |
| 153 | def print_results(results): |
| 154 | """Print scan results in a formatted way""" |
no test coverage detected