-
Notifications
You must be signed in to change notification settings - Fork 1
/
macit.lua
72 lines (53 loc) · 12.6 KB
/
macit.lua
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
#!/usr/bin/lua
-- report any device that makes a prob-request
-- put the router in monitor mode iw phy phy0 interface add mon0 type monitor
-- then enable the interface ifconfig mon0 up d
-- opkg install luasocket
-- opkg install tcpdump
function get_packet(line)
if not line then
return nil
end
packet = {}
packet = string.gsub(line,'['..'>,"'..']','') -- remove >," from tcpdump results
words = {}
for word in packet:gmatch("%S+") do
table.insert(words, word)
-- print (words, word)
end
return packet, words
end
function main_loop()
local http=require'socket.http'
local packet = {}
local f
local last = 0
local count = 0
newmac = 'empty'
oldmac = 'empty'
now = socket.gettime()
-- lets see what's asking for a connection
-- f = io.popen("tcpdump -enU -s 128 -i mon0 type mgt subtype probe-req")
f = io.popen("grep -q mon0 /proc/net/dev || /usr/sbin/iw phy phy0 interface add mon0 type monitor /sbin/ifconfig mon0 up; /usr/sbin/tcpdump -enUl -s 128 -i mon0 -y IEEE802_11_RADIO type mgt subtype
print ('hello')
while true do -- big loop, waiting for packets
packet = get_packet(f:read("*l")) --
-- print(packet, '\n')
-- for k, v in pairs( words ) do
-- print(k, v)
-- end
-- newmac=words[15] -- station/device MAC
newmac=words[13] -- station/device MAC
now = socket.gettime()
if newmac == oldmac then
count = count + 1
print(count,' ',now, ' ',' repeat MAC adddress is = '..newmac)
else
count = 0
print(count,' ',now,' ',' MAC adddress is = '..newmac)
oldmac = newmac
end
end
io.close(f)
end
main_loop()