-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifi-m.py
64 lines (48 loc) · 1.81 KB
/
wifi-m.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
#!bin/bash sudo python
import optparse
import scapy.all as scapy
from scapy.layers.inet import IP, ICMP
def getArguments():
parser = optparse.OptionParser()
parser.add_option("-t", "--target", dest="target",
help="target IP/ IP range")
args_options, arguments = parser.parse_args()
return args_options
def createPacket(ip):
arp_request = scapy.ARP(pdst=ip) # create a ARP request object by scapy
# We have set the destination
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast / arp_request
return (arp_request_broadcast)
def transmitPacket(packet):
success_list, failure_list = scapy.srp(packet, timeout=1)
return success_list
def getOS(ip_addr):
ttl_values = {32: "Windows", 60: "MAC OS", 64: "Linux",
128: "Windows", 255: "Linux 2.4 Kernal"}
ans = scapy.sr1(IP(dst=str(ip_addr)) / ICMP(), timeout=1, verbose=0)
if ans:
if ans.ttl in ttl_values:
return ttl_values.get(ans.ttl)
else:
return "could not figure the OS version"
else:
return "Packets could not send successfully"
def parseResponse(success_list):
targets = []
for success in success_list:
entry = {'ip': success[1].psrc, 'mac': success[1].hwsrc}
targets.append(entry)
return targets
def print_analysis(element_entries):
print("IP\t\t\tMAC Address\t\t\tOPERATING SYSTEM")
print("." * 100)
for element in entries:
print(element["ip"] + "\t\t" + element['mac'] +
"\t\t" + getOS(element["ip"]) + "\n")
options = getArguments()
if options.target is not None:
broadcast_packets = createPacket(options.target)
success_packets = transmitPacket(broadcast_packets)
entries = parseResponse(success_packets)
print_analysis(entries)