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

Function scan_network

actions/Scanner.py:114–151  ·  view source on GitHub ↗

Main function to scan network

(interface='eth0', port_range='1-1000', quick=False)

Source from the content-addressed store, hash-verified

112 return {'hostname': 'Error', 'ports': []}
113
114def 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
153def print_results(results):
154 """Print scan results in a formatted way"""

Callers 1

Scanner.pyFile · 0.85

Calls 5

check_requirementsFunction · 0.85
run_arp_scanFunction · 0.85
run_nmap_scanFunction · 0.85
appendMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected