-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathARPScanner.py
66 lines (50 loc) · 1.68 KB
/
ARPScanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import argparse
import signal
from sys import exit
from scapy.layers.l2 import Ether, ARP, srp, conf
def keyboard_interrupt_handler(interrupt_signal, frame):
"""
Keyboard (CTRL + C) interrupt function
"""
print("Scanning stopped")
print("KeyboardInterrupt ID: {} {} has been caught.".format(interrupt_signal, frame))
exit(1)
def arp_scan():
"""
Scanning function
"""
global interface
global network
conf.verb = 1
ans, uans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=network), timeout=3, iface=interface, inter=0.1)
for snd, rcv in ans:
print("IP: {:<15} MAC: {}".format(rcv.psrc, rcv.hwsrc))
def run_app():
"""
Main function to parse arguments and run
"""
global interface
global network
description = 'Simple ARP scanner'
epilog = 'The author of this code take no responsibility for your use or misuse'
parser = argparse.ArgumentParser(prog='ARPScanner.py', description=description, epilog=epilog)
parser.add_argument("interface", help="Your interface")
parser.add_argument("network", help="Your target ip or network CIDR")
args = parser.parse_args()
if len(args.interface) < 1:
print('You did not provide any interface?')
exit(1)
else:
interface = args.interface
if len(args.network) < 1:
print('You did not provide any ip range?')
exit(1)
else:
network = args.network
print("Start ARP scanning on interface {} on network {}".format(interface, network))
arp_scan()
if __name__ == "__main__":
interface = network = None
signal.signal(signal.SIGINT, keyboard_interrupt_handler)
run_app()