diff --git a/WIFI_sniffer/a_tst_sort.lua.190209.1507 b/WIFI_sniffer/a_tst_sort.lua.190209.1507 deleted file mode 100644 index 0eb678d..0000000 --- a/WIFI_sniffer/a_tst_sort.lua.190209.1507 +++ /dev/null @@ -1,118 +0,0 @@ --- Scripts pour tester le tri (sort) d'un tableau d'adresse MAC en fonction du signal de réception --- pour les tests on charge un fichier CSV de d'adresse MAC sniffées précédemment --- source: https://wxlua.developpez.com/tutoriels/lua/general/cours-complet/#L6-f --- source: https://wxlua.developpez.com/tutoriels/lua/general/cours-complet/#L13-g - -print("\n a_tst_sort.lua zf190208.1734 \n") - -zmac_adrs={} - - -function zshow() - i=1 - for k, v in pairs(zmac_adrs) do - print(i..", ", k..", ", zmac_adrs[k]["zname"], zmac_adrs[k]["zrssi"], zmac_adrs[k]["ztime"]) - i=i+1 - end -end - -function zload_tableau() - filename="tst_sniffer_wifi1.csv" - if file.open(filename, "r") then - repeat - local line=file.read('\n') - if line then --- print("line: "..line) - local zfield = {} local zpart="" - for zpart in line:gmatch("[^,]+") do - zfield[#zfield+1] = zpart - end - -- :sub(1, -2) , ça enlève le \n à la fin de la ligne lors de la lecture du fichier ! - zmac_adrs[zfield[2]]={["zname"]=zfield[3],["zrssi"]=zfield[4], ["ztime"]=zfield[5]:sub(1, -2)} - end - until not line - file.close() - end -end - - -zload_tableau() ---zshow() - -print("tableau chargé") --important, c'est pour attendre que le tableau soit complètement chargé ! -zshow() - ---[[ -test_sort1=tmr.create() -tmr.alarm(test_sort1, 2.5*1000, tmr.ALARM_SINGLE, function() - zshow() -end) -]] - - - -function zsort_tableau() - print("tri du tableau") - table.sort(zmac_adrs, function(a,b) return a.zrssi < b.zrssi end) - - -end - -function zshow2() - i=1 - - --for i,v in ipairs(zmac_adrs) do print(v.zrssi) end - for j,v in pairs(zmac_adrs) do - print(i,j) - i=i+1 - end - --- i=1 --- for k, v in pairs(zmac_adrs) do --- print(i..", ", k..", ", zmac_adrs[k]["zname"], zmac_adrs[k]["zrssi"], zmac_adrs[k]["ztime"]) --- i=i+1 --- end -end - - -function toto() - local animals = { - {name = "bunny", size = 4}, - {name = "mouse", size = 1}, - {name = "cow", size = 30} - } - -- sort animals by size descending - table.sort(animals, function(a,b) return a.size > b.size end) - - for i,v in ipairs(animals) do print(v.name) end -end - - - - ---[[ -zload_tableau() -zsort_tableau() -zshow() -zshow2() - -]] - - - ---[[ -zshow() -]] - -function zround(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end - - ---[[ -zload_tableau() -zshow() -]] - - diff --git a/WIFI_sniffer/a_tst_sort.lua.190209.1932 b/WIFI_sniffer/a_tst_sort.lua.190209.1932 deleted file mode 100644 index 347c7f5..0000000 --- a/WIFI_sniffer/a_tst_sort.lua.190209.1932 +++ /dev/null @@ -1,120 +0,0 @@ --- Scripts pour tester le tri (sort) d'un tableau d'adresse MAC en fonction du signal de réception --- pour les tests on charge un fichier CSV de d'adresse MAC sniffées précédemment --- source: https://wxlua.developpez.com/tutoriels/lua/general/cours-complet/#L6-f --- source: https://wxlua.developpez.com/tutoriels/lua/general/cours-complet/#L13-g - -print("\n a_tst_sort.lua zf190209.1512 \n") - -zmac_adrs={} -zmac_adrs_index={} - - - -function zshow() - i=1 - for k, v in ipairs(zmac_adrs) do - print(i..", "..k, zmac_adrs[k]["adrs"]..", ".. zmac_adrs[k]["zname"], zmac_adrs[k]["zrssi"], zmac_adrs[k]["ztime"]) - i=i+1 - end -end - -function zload_tableau() - filename="tst_sniffer_wifi1.csv" - if file.open(filename, "r") then - repeat - local line=file.read('\n') - if line then --- print("line: "..line) - local zfield = {} local zpart="" - for zpart in line:gmatch("[^,]+") do - zfield[#zfield+1] = zpart - end - -- :sub(1, -2) , ça enlève le \n à la fin de la ligne lors de la lecture du fichier ! - --zmac_adrs[#zmac_adrs+1]={adrs=zfield[2], zname=zfield[3], zrssi=zfield[4], ztime=zfield[5]:sub(1, -2)} - - --zmac_adrs[#zmac_adrs+1]={adrs="b8:d7:af:a6:bd:86", zname=0, zrssi=0, ztime=0} - zmac_adrs[#zmac_adrs+1]=line:sub(1, -2) - - --zmac_adrs[#zmac_adrs+1]={adrs="b8:d7:af:a6:bd:86", zname="tototutu", zrssi=-50, ztime= 0} - --zmac_adrs_index[zfield[2]]=#zmac_adrs - end - until not line - file.close() - end -end - - ---zload_tableau() - ---print("tableau chargé") --important, c'est pour attendre que le tableau soit complètement chargé ! ---zshow() - - -function zsort_tableau() - print("tri du tableau") - table.sort(zmac_adrs, function(a,b) return a.zrssi < b.zrssi end) -end - - - -function test_ram_table() - zmac_adrs={} - for i=1, 70 do - print(i) - --zmac_adrs[#zmac_adrs+1]={adrs="b8:d7:af:a6:bd:86", zname=0, zrssi=-50, ztime= 0} - zmac_adrs[i]={adrs="b8:d7:af:a6:bd:86", zname=0, zrssi=-50, ztime= 0} - end -end - -function zshow2() - for i=1, #zmac_adrs do - print(i,zmac_adrs[i]) - zindex, zadrs, zname, zrssi, ztime = zmac_adrs[i]:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)") - print("toto",zindex, zadrs, zname, zrssi, ztime, "tutu") - end -end - - ---[[ - - -string = "71,02:e6:ac:b3:6e:40,0,-43,0" -t1, t2, t3, t4, t5 = string:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)") -print(t1, t2, t3, t4, t5) - - - -test_ram_table() - -zload_tableau() -zsort_tableau() -zshow() -zshow2() - -print(zmac_adrs_index["02:ec:f1:a1:c8:29"]) -print(zmac_adrs[70].adrs) - -zmac_adrs=nil -zmac_adrs={} - -zmac_adrs_index=nil -zmac_adrs_index={} - - -zmac_adrs_index={} -zmac_adrs_index["toto"]=3 -print(zmac_adrs_index["toto"]) - - -]] - - - - -function zround(num, dec) - local mult = 10^(dec or 0) - return math.floor(num * mult + 0.5) / mult -end - - - diff --git a/WIFI_sniffer/b.lua b/WIFI_sniffer/b.lua index 05928aa..fcbae7f 100644 --- a/WIFI_sniffer/b.lua +++ b/WIFI_sniffer/b.lua @@ -1,35 +1,86 @@ -- Scripts pour tester le sniffer de smartphone qui essaient de se connecter sur des AP WIFI -- source: https://nodemcu.readthedocs.io/en/dev/modules/wifi/#wifieventmonregister -print("\n b.lua zf190202.1534 \n") +print("\n b.lua zf190209.2017 \n") --f= "set_time.lua" if file.exists(f) then dofile(f) end -- apzuzu6 38:2c:4a:4e:d3:d8 zmac_adrs={} -zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf"} -zmac_adrs["cc:c0:79:7d:f5:d5"]={["zname"]="S7 Mélanie"} -zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="MAC zf"} -zmac_adrs["d8:30:62:5a:d6:3a"]={["zname"]="IMAC Maman"} -zmac_adrs["88:e9:fe:6b:ec:1e"]={["zname"]="MAC Luc"} -zmac_adrs["0c:2c:54:b3:c5:1a"]={["zname"]="HU Nicolas"} -zmac_adrs["c0:a6:00:bf:4e:43"]={["zname"]="IPHONE Maeva"} - - - +zmac_adrs[#zmac_adrs+1]="b8:d7:af:a6:bd:86,S7 zf,0,0,0" +zmac_adrs[#zmac_adrs+1]="cc:c0:79:7d:f5:d5,S7 Melanie,0,0,0" +zmac_adrs[#zmac_adrs+1]="5c:f9:38:a1:f7:f0,MAC zf,0,0,0" +zmac_adrs[#zmac_adrs+1]="d8:30:62:5a:d6:3a,IMAC Maman,0,0,0" +zmac_adrs[#zmac_adrs+1]="88:e9:fe:6b:ec:1e,MAC Luc,0,0,0" +zmac_adrs[#zmac_adrs+1]="0c:2c:54:b3:c5:1a,HU Nicolas,0,0,0" +zmac_adrs[#zmac_adrs+1]="c0:a6:00:bf:4e:43,IPHONE Maeva,0,0,0" +zmac_adrs[#zmac_adrs+1]="80:58:f8:44:09:ce, ,-30,0,0" +zmac_adrs[#zmac_adrs+1]="02:07:49:35:67:10, ,-58,0,0" +zmac_adrs[#zmac_adrs+1]="c0:ee:fb:4a:ff:28, ,-55,0,0" +zmac_adrs[#zmac_adrs+1]="da:a1:19:ed:93:84, ,-59,0,0" +zmac_adrs[#zmac_adrs+1]="02:c5:a0:96:05:bd, ,-32,0,0" +zmac_adrs[#zmac_adrs+1]="da:a1:19:a6:a0:93, ,-56,0,0" +zmac_adrs[#zmac_adrs+1]="46:79:22:70:f5:b8, ,-59,0,0" +zmac_adrs[#zmac_adrs+1]="86:27:18:64:f8:c0, ,-57,0,0" +zmac_adrs[#zmac_adrs+1]="da:a1:19:89:2c:80, ,-59,0,0" +zmac_adrs[#zmac_adrs+1]="da:a1:19:01:85:98, ,-47,0,0" function zshow() - i=1 - for k, v in pairs(zmac_adrs) do - print(i..", ", k..", ", zmac_adrs[k]["zname"], zmac_adrs[k]["zrssi"], zmac_adrs[k]["ztime"]) - i=i+1 + for i=1, #zmac_adrs do +-- print(i,zmac_adrs[i]) + zadrs, zname, zrssi, ztime0, ztime1 = zmac_adrs[i]:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)") + print(i.."-"..zadrs..", "..zname..", "..zrssi..", "..ztime0..", "..ztime1.."-") end end + +function zsplit(zline) + zadrs, zname, zrssi, ztime0, ztime1 = zline:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)") + print("-", zadrs, zname, zrssi, ztime0, ztime1,"-") +end + +function zmerge() + zline=zadrs..","..zname..","..zrssi..","..ztime0..","..ztime1 + print(zline) + return zline +end + +function find_adrs(zadrs) + for i=1, #zmac_adrs do + if zadrs == zmac_adrs[i]:match("([^,]+),[^,]+,[^,]+,[^,]+,[^,]+") then + print(zmac_adrs[i]) + return i + end + end + return 0 +end + +function zsort_rssi() + print("tri du tableau") + table.sort(zmac_adrs, function(a,b) + return a:match("[^,]+,[^,]+,([^,]+),[^,]+,[^,]+") < b:match("[^,]+,[^,]+,([^,]+),[^,]+,[^,]+") + end) +end + + + --[[ zshow() +zsort_rssi() + +zsplit(zmac_adrs[1]) +print(zmerge()) + +print(find_adrs("88:e9:fe:6b:ec:1e")) +print(find_adrs("da:a1:19:b6:6b:50")) + +print(find_adrs("88:e9:fe:6b:ec:1e")) +zsplit(zmac_adrs[5]) +zrssi=-45 ztime0="10:19" ztime1="10:19" +zmac_adrs[5]=zmerge() +print(find_adrs("88:e9:fe:6b:ec:1e")) ]] function zround(num, dec) @@ -38,8 +89,7 @@ function zround(num, dec) end function zsniff(T) - - if T.RSSI > -60 then + if T.RSSI > -160 then -- print("\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI) -- ztime() if zmac_adrs[T.MAC] == nil then @@ -58,7 +108,8 @@ function zsniff(T) end end -wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, zsniff) +--wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, zsniff) + --[[ wifi.eventmon.unregister(wifi.eventmon.AP_PROBEREQRECVED) zshow()