|
| 1 | +import scapy.all as scapy |
| 2 | +import optparse |
| 3 | + |
| 4 | + |
| 5 | +def get_arguments(): # function to pass input in console |
| 6 | + parser = optparse.OptionParser() |
| 7 | + parser.add_option("-t", "--target", dest="target", |
| 8 | + help="Target IP / IP range.") |
| 9 | + options, arguments = parser.parse_args() |
| 10 | + return options |
| 11 | + |
| 12 | + |
| 13 | +def scan(ip): |
| 14 | + arp_request = scapy.ARP(pdst=ip) # destinationn ip |
| 15 | + broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff") |
| 16 | + arp_request_broadcast = broadcast/arp_request |
| 17 | + # print(arp_request_broadcast.summary()) |
| 18 | + # arp_request_broadcast.show() |
| 19 | + answered_list = scapy.srp(arp_request_broadcast, |
| 20 | + timeout=1, verbose=False)[0] |
| 21 | + # print(answered_list.summary()) |
| 22 | + # print(unanswered.summary()) |
| 23 | + |
| 24 | + clients_list = [] |
| 25 | + for element in answered_list: |
| 26 | + clients_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc} |
| 27 | + clients_list.append(clients_dict) |
| 28 | + # print(element[1].psrc +"\t\t"+element[1].hwsrc) |
| 29 | + |
| 30 | + return(clients_list) |
| 31 | + |
| 32 | + |
| 33 | +def print_result(result_list): |
| 34 | + print("IP\t\t\tMAC ADDRESS\n..........................................................................") |
| 35 | + for client in result_list: |
| 36 | + print(client["ip"]+"\t\t"+client["mac"]) |
| 37 | + |
| 38 | + |
| 39 | +options = get_arguments() |
| 40 | +scan_result = scan(options.target) |
| 41 | +print_result(scan_result) |
0 commit comments