-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashit.lua
67 lines (46 loc) · 3.58 KB
/
dashit.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
#!/usr/bin/lua
-- body,c,l,h = http.request('http://maker.ifttt.com/trigger/DASHit/with/key/yourkeyhere')
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 delay = 2
-- f = io.popen("tcpdump -e -i wls1 arp") -- desktop arp
f = io.popen("tcpdump -e -i wls1")
-- f = io.popen("tcpdump -e -i br-lan") -- glnet router
DASHmac = 'empty'
now = socket.gettime()
-- delta = now
print ('hello')
while true do -- big loop, waiting for arp packets
now = socket.gettime()
packet = get_packet(f:read("*l")) --
-- print(packet, '\n')
-- for k, v in pairs( words ) do
-- print(k, v)
-- end
if words[13]=='BOOTP/DHCP' and words[11]=='localhost.bootpc' then
DASHmac = words[2]
print(now, ' DASH MAC adddress is = '..DASHmac)
end
-- print('button pushed '..DASHmac)
-- body,c,l,h = http.request('http://maker.ifttt.com/trigger/DASHit/with/key/yourkeyhere')
-- print(body,c,l,h)
end
io.close(f)
end
main_loop()