This repository was archived by the owner on Dec 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathap_socket.py
executable file
·97 lines (74 loc) · 1.93 KB
/
ap_socket.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# +++++++++++++++++++++++++++++++++++++++++
#
# WLAN BEACON FRAME EXTRACTOR
# +++++++++++++++++++++++++++++++++++++++++
#
#
# Author : SSB
# surajsinghbisht054@gmail.com
# http://bitforestinfo.blogspot.com
# github.com/surajsinghbisht054
#
#
# This Script Is Created For Educational And Practise Purpose Only
#
#
# import module
import socket
import struct
# create Socket
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
# bind with monitor mode interface
s.bind(('mon0',0x0003))
# function for formating mac addresses
def addr(s):
return "{}{}:{}{}:{}{}:{}{}:{}{}:{}{}".format(*s.upper())
# Founded Access Point List
ap_list = []
# loop
while True:
# Sniff Packet and get packet from list
pkt = s.recvfrom(2048)[0]
# Check RadioTap Header Frame In Packet
if pkt[2:4]=='$\x00':
# Get Total Length Of RadioTap Header Packet Bytes
len_of_header = struct.unpack('h', pkt[2:4])[0]
# Extract RadioTap Header
radio_tap_header_frame = pkt[:len_of_header].encode('hex')
# Now, assume that next frame from radiotap is Beacon Frame
beacon_frame = pkt[len_of_header:len_of_header+24].encode('hex')
# Frame Type
f_type = beacon_frame[:2]
# Extract Addr1
addr1 = beacon_frame[8:20]
# Extract Addr2
addr2 = beacon_frame[20:32]
# Extract Addr3
addr3 = beacon_frame[32:44]
# Try To Extract SSID if present
try:
len_of_ssid = ord(pkt[73])
ssid = pkt[74:74+len_of_ssid]
except:
ssid = "Unknown"
# Verify that extract frame is a beacon frame and not printed yet
if addr2 not in ap_list and f_type=='80':
# append addr2 in ap_list
ap_list.append(addr2)
# Print Info
print """
++++++++++ [ Beacon Frame ] ++++++++++++++++++++
Frame Type : {}
SSID : {}
Receiver : {}
Transmitter : {}
Source : {}
""".format(f_type, # Frame Type
ssid , # SSID
addr(addr1), # Addr1
addr(addr2), # Addr2
addr(addr3) # Addr3
)