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

Function run_arp_scan

actions/Scanner.py:24–58  ·  view source on GitHub ↗

Run ARP scan to discover devices on local network

(interface='eth0')

Source from the content-addressed store, hash-verified

22 sys.exit(1)
23
24def run_arp_scan(interface='eth0'):
25 """Run ARP scan to discover devices on local network"""
26 print(f"[*] Running ARP scan on interface {interface}...")
27
28 try:
29 # Run arp-scan
30 result = subprocess.run(
31 ['arp-scan', '--localnet', f'--interface={interface}'],
32 capture_output=True,
33 text=True,
34 check=True
35 )
36
37 devices = []
38 # Parse arp-scan output
39 for line in result.stdout.split('\n'):
40 # Match lines with IP, MAC, and vendor info
41 match = re.match(r'(\d+\.\d+\.\d+\.\d+)\s+([0-9a-fA-F:]{17})\s+(.*)', line)
42 if match:
43 devices.append({
44 'ip': match.group(1),
45 'mac': match.group(2),
46 'vendor': match.group(3).strip()
47 })
48
49 print(f"[+] Found {len(devices)} devices via ARP scan")
50 return devices
51
52 except subprocess.CalledProcessError as e:
53 print(f"Error running arp-scan: {e}")
54 print("Note: arp-scan requires root privileges")
55 return []
56 except FileNotFoundError:
57 print("Error: arp-scan not found")
58 return []
59
60def run_nmap_scan(ip_address, port_range='1-1000'):
61 """Run Nmap scan on specific IP to get hostname and open ports"""

Callers 1

scan_networkFunction · 0.85

Calls 2

appendMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected