-
Notifications
You must be signed in to change notification settings - Fork 0
/
sike.py
48 lines (39 loc) · 1.22 KB
/
sike.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
from scapy.all import ARP, Ether, srp, arping
import json
maclookup = {}
with open("MACLookup.json", "r") as read_file:
maclookup = json.load(read_file)
"""
target_ip = "192.168.0.1/24"
# IP Address for the destination
# create ARP packet
arp = ARP(pdst=target_ip)
# create the Ether broadcast packet
# ff:ff:ff:ff:ff:ff MAC address indicates broadcasting
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
# stack them
packet = ether/arp
result = srp(packet, timeout=3, verbose=0)[0]
# a list of clients, we will fill this in the upcoming loop
clients = []
for sent, received in result:
# for each response, append ip and mac address to `clients` list
clients.append({'ip': received.psrc, 'mac': maclookup.get(received.hwsrc, received.hwsrc)})
# print clients
print("Available devices in the network:")
print("IP" + " "*18+"MAC")
for client in clients:
print("{:16} {}".format(client['ip'], client['mac']))
"""
things = []
ans,unans = arping("192.168.0.1/24", verbose=0)
for s,r in ans:
mac = r[Ether].src
if not mac in things:
things.append(mac)
#print("{} {}".format(r[Ether].src,s[ARP].pdst))
print("Pre processed")
print(things)
things = [maclookup.get(x, x) for x in things]
print("Post processed:")
print(things)