Cov txheej txheem:

Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb: 11 Kauj Ruam
Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb: 11 Kauj Ruam

Video: Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb: 11 Kauj Ruam

Video: Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb: 11 Kauj Ruam
Video: Qhia Nkag Mus Rau Email - GMAIL, Maiv Xyooj 2024, Hlis ntuj nqeg
Anonim
Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb
Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb
Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb
Android/iOS App nkag mus rau koj li OpenWrt Router nyob deb

Kuv nyuam qhuav yuav ib lub router tshiab (Xiaomi Mi Router 3G). Thiab ntawm chav kawm, qhov tshiab, zoo heev ntawm cov khoom siv tau txhawb kuv kom pib ua haujlwm ntawm txoj haujlwm no;)

Kauj Ruam 1: Kuv xav tias, koj tau OpenWrt lawm…

Kuv xav tias, koj tau OpenWrt lawm…
Kuv xav tias, koj tau OpenWrt lawm…

Kuv yuav tsum tau teeb tsa OpenWrt thawj zaug … Feem ntau, kuv ua raws phau ntawv qhia no (tshwj xeeb rau tus qauv router no): https://dzone.com/articles/hacking-into-xiaomi-mi-…Thaum ua haujlwm ntawm no, Kuv pom daim vis dis aus txaus: Openwrt teeb tsa, WiFi tus qauv, Tus Hluas Nkauj Flashing. Wow Kuv luag heev li!:)

Ua tib zoo mloog! Txhim kho OpenWrt tuaj yeem cib koj lub router. Tab sis thaum ua tiav, nws qhib lub zog tag nrho thiab tswj hwm. Kuv tsis muaj lub siab tawv txaus los muab cov lus qhia ntawm no, vim tias lawv yuav txawv rau txhua tus qauv router.

Tab sis yog tias koj twb muaj OpenWrt ntawm koj lub router, koj yuav tuaj yeem pib nrog qhov kev qhia no hauv lub sijhawm

BTW, qee cov phiaj xwm txhim kho tuaj nrog OpenWrt tawm ntawm lub thawv, zoo li Onion Omega, VoCore, LinkIt Smart 7688 thiab lwm yam. Cov ntawv qhia no tseem piav qhia qee cov tswv yim yooj yim tom qab tsim cov apps, yog li koj tuaj yeem hloov kho nws yooj yim los ua haujlwm nrog Raspberry Pi thiab nyiam.

Txog qhov haujlwm no, Kuv yuav siv feem ntau siv software ua ntej (muaj nyob ntawm ib qho OpenWrt-qhib router). Tab sis rau qee qhov ua haujlwm tau zoo, Kuv yuav tsum tau teeb tsa pob ntxiv. Qhov no ua tiav tsuas yog ob peb nyem, yog li kuv yuav suav nrog cov lus qhia ntawm no.

Tsis tas li, kuv xav tias koj twb paub lawm:

  • Yuav qhib/siv SSH davhlau ya nyob twg rau koj li OpenWrt router
  • Yuav ua li cas upload/kho cov ntaub ntawv ntawm koj lub router (siv FileZilla lossis scp/sftp)
  • Yuav ua li cas ua haujlwm nrog Linux console

Kauj Ruam 2: Software thiab Cov Cuab Yeej

Software thiab Cuab Yeej
Software thiab Cuab Yeej

Ntawm lub xov tooj ntawm tes, Kuv siv Blynk. Nws muab iOS thiab Android apps los tswj hwm txhua yam khoom siv. Koj tuaj yeem yooj yim tsim cov duab zoo nkauj cuam tshuam rau txhua qhov koj cov phiaj xwm los ntawm kev yooj yim rub thiab nqis cov cuab yeej, sab xis ntawm koj lub smartphone. Blynk feem ntau siv nrog Arduino, Raspberry Pi, thiab lwm yam. Tab sis vim li cas ho tsis khiav nws ntawm tus kheej router?;)

Ntawm lub cuab yeej kuv yuav siv Lua los sau cov haujlwm uas xav tau Kuv kuj tseem tuaj yeem siv Python lossis Node.js, tab sis hmoov tsis cov kev xaiv no ib txwm tsis muaj, vim tsis muaj peev txheej ntawm qee tus routers.or C/C ++, tab sis nws tsis yooj yim los ua haujlwm nrog (rov ua dua tshiab rau txhua qhov kev hloov pauv, thiab lwm yam) Ntawm qhov tod tes, Lua tau teeb tsa ua ntej, yooj yim siv thiab kawm. Nws tau siv los ntawm lub vev xaib tsis raug, LuCI.

Kauj Ruam 3: Tsim Tsawg App

Pib nrog Blynk thiab Lua yog ib qho yooj yim li:

  • Rub tawm Blynk App (los ntawm App Store, Google Play)
  • Tsim ib qhov haujlwm tshiab thiab tau txais Auth Token
  • Ua raws li Blynk Lua cov lus qhia teeb tsa rau OpenWrt.

Siv SSH txhawm rau nkag mus rau koj lub router console. Tom qab khiav qhov piv txwv tsis raug:

lua./examples/client.lua

Peb yuav tsum pom qee yam zoo li no:

Txuas …

SSL tuav… Npaj.

Uas txhais tau tias kev nyab xeeb, ob-txoj kev txuas mus rau lub app tau tsim! YAY!

Tam sim no peb tuaj yeem txuas ntxiv qhov piv txwv muab, yog li nws ua qee yam ntxim nyiam. Kuv tau tsim ib daim qauv ntawm qhov piv txwv no los kho nws:

cp./examples/client.lua./blynkmon.lua

Kauj Ruam 4: Ntxiv Qee Cov Ntaub Ntawv: Tus naj npawb ntawm Cov Neeg Siv Khoom, WAN IP Chaw Nyob, Sijhawm Sijhawm

Lub tswv yim yooj yim yog kom tau txais cov ntaub ntawv los ntawm OS ib ntus, ua qee qhov kev suav yooj yim yog xav tau, thiab tom qab ntawd xa cov txiaj ntsig mus rau Blynk rau tso saib.

Hauv Linux/OpenWrt, peb muaj ntau txoj hauv kev kom tau txais cov ntaub ntawv system:

  • Khiav ib lo lus txib, thiab cais cov ntawv nws tso tawm
  • Khiav ib lo lus txib, thiab saib cov cai tawm nws rov los
  • Nyeem cov ntaub ntawv kaw lus, nyob hauv/proc/thiab/sys/class/directories

Tam sim no kuv xav qhia tus lej ntawm cov khoom siv sib txuas.

Thaum kuv khiav miv/proc/net/arp ntawm lub console, nws tawm cov npe ntawm cov cuab yeej paub, nrog rau lawv MAC thiab IP chaw nyob:

IP chaw nyob HW hom Chij HW chaw nyob Mask Mask

192.168.10.206 0x1 0x2 78: 02: f8: fb: d6: bf * br-lan 194. -------------------- 0x1 0x2 4c: 5e: 0c: 14: e0: 5c * eth0.2 192.168.10.162 0x1 0x0 04: b1: 67: 2f: e3: 74 * br-lan

Peb tuaj yeem txheeb nws ncaj qha hauv Lua, tab sis feem ntau nws yooj yim dua rau siv cov cuab yeej siv tshwj xeeb. Nws ntawm Linux, cov no yog grep, taub hau, tus tw, txiav, wc, awk.

Txhawm rau kom tau txais tus lej ntawm cov neeg siv khoom los ntawm arp cov zis, Kuv yuav tsum lim lub rooj (tshem tawm cov khoom tsis cuam tshuam) thiab suav cov kab ntawm kab, uas ua rau cov lus txib hauv qab no:

miv/proc/net/arp | grep br-lan | Cov grep0x2 wb wc -li

Cia peb sim nws:

hauv paus@router: ~/lua-blynk# miv/proc/net/arp | grep br-lan | Cov grep0x2 wb wc -li

1

Zoo kawg. Tam sim no peb tau txais lub tswv yim ntawm yuav ua li cas peb tuaj yeem sau tag nrho cov ntaub ntawv xav tau. Cia peb siv nws kom ua kom peb cov cai huv thiab nthuav dav, cia peb tsim qee qhov kev pabcuam:

muaj nuj nqi exec_out (cmd)

cov ntaub ntawv hauv zos = io.popen (cmd) yog tias tsis ua ntaub ntawv thov rov qab nil kawg hauv zos tso tawm = file: nyeem ('*tag nrho') file: kaw () print ("Run:"..cmd.. " ->".. output) rov qab tso tawm qhov kawg ua haujlwm read_file (txoj hauv kev) cov ntaub ntawv hauv zos = io.open (txoj hauv kev, "rb") yog tias tsis ua ntaub ntawv thov rov qab nil kawg cov ntsiab lus hauv zos = ntawv: nyeem "*a" file: kaw () print ("Nyeem: "..path.." -> "..content) xa cov ntsiab lus kawg

Siv cov khoom siv hluav taws xob no, tam sim no peb tuaj yeem siv qhov tseeb cov ntaub ntawv khaws cov haujlwm:

muaj nuj nqi getArpClients ()

rov tonumber (exec_out ("miv/proc/net/arp | grep br -lan | grep 0x2 | wc -l")) kawg ua haujlwm getUptime () rov tonumber (exec_out ("miv/proc/uptime | awk '{luam tawm $ 1 } '")) kawg ua haujlwm getWanIP () rov qab exec_out (" ifconfig eth0.2 | grep' inet addr: '| txiav -d: -f2 | awk' {luam $ 1} '") kawg

Koj tuaj yeem ua ntu ntu ntawm cov lus txib hauv plhaub, kom nkag siab tob txog nws ua haujlwm li cas, thiab kho nws raws li koj xav tau.

Qhov yooj yim tshaj yog xa cov ntaub ntawv mus rau Blynk App. Qhov piv txwv tsis raug twb teeb tsa lub sijhawm, uas khiav qee qhov chaws txhua 5 vib nas this, yog li peb tsuas yog siv nws:

tmr1 hauv zos = Timer: tshiab {ncua = 5000, func = muaj nuj nqi ()

blynk: virtualWrite (10, getArpClients ()) blynk: virtualWrite (11, string.format ("%. 1f h", getUptime ()/60/60)) blynk: virtualWrite (12, getWanIP ()) kawg)

Hauv app, peb ntxiv 3 daim ntawv cim npe, thiab muab lawv rau Virtual Pins 10, 11, 12 raws li.

Thaum qhov no ua haujlwm, nws zoo li tsis muaj txiaj ntsig, vim WAN IP lossis tus lej ntawm cov neeg siv khoom tsis hloov kho tas li. Let's kho qhov no

Txog WAN IP, peb txav nws mus rau tus tuav haujlwm txuas nrog. Nws yuav khiav txhua lub sijhawm router teeb tsa kev sib txuas rau Blynk Cloud. Qhov no yuav tsum txaus:

blynk: ntawm ("txuas nrog", muaj nuj nqi ()

print ("Npaj.") blynk: virtualWrite (12, getWanIP ()) kawg)

Txog Uptime thiab Cov Neeg Siv Tus lej, peb tsim lub sijhawm sib cais nrog 5 feeb. ncua sijhawm:

tmr2 hauv zos = Timer: tshiab {ncua = 5*60*1000, func = muaj nuj nqi ()

blynk: virtualWrite (10, getArpClients ()) blynk: virtualWrite (11, string.format ("%. 1f h", getUptime ()/60/60)) kawg}

Kauj Ruam 5: Kev Tswj WiFi: ON/OFF

Kev Tswj WiFi: ON/OFF
Kev Tswj WiFi: ON/OFF

Txog tam sim no, peb tsuas yog tau txais qee cov ntaub ntawv los ntawm lub cuab yeej. Peb sim sim tswj nws!

blynk: ntawm ("V20", muaj nuj nqi (param)

yog param [1] == "1" ces os.execute ("wifi up") lwm os.execute ("wifi down") kawg kawg)

Ntawm sab app, Kuv nyuam qhuav ntxiv khawm widget (hom: Hloov) thiab muab nws rau V20.

Qhov ntawd yog nws. Zoo kawg.

Kauj Ruam 6: Cov Txheej Txheem Txheej Txheem Txheej Txheem

Qhov System Stats Chart
Qhov System Stats Chart
Qhov System Stats Chart
Qhov System Stats Chart

muaj nuj nqi getCpuLoad ()

rov tonumber (exec_out ("saum -bn1 | grep 'CPU:' | lub taub hau -n1 | awk '{luam $ 2+$ 4}'")) kawg ua haujlwm getRamUsage () rov tonumber (exec_out ("dawb | grep Mem | awk ' {luam tawm ($ 3- $ 7)/$ 2 * 100.0} '")) kawg

Peb kuj yuav tsum xa cov ntaub ntawv mus rau Blynk (cia peb siv tmr1 dua):

tmr1 hauv zos = Timer: tshiab {ncua = 5000, func = muaj nuj nqi ()

blynk: virtualWrite (5, getCpuLoad ()) blynk: virtualWrite (6, getRamUsage ()) kawg}

Ntawm App Sab, ntxiv SuperChart widget. Ntxiv CPU, RAM datastreams thiab muab rau V5, V6.

Kauj Ruam 7: HDD Spinning Status

Kuv tus router muaj tus tsav sab nraud HDD txuas nrog ua Network Txuas Txuas Cov Khoom. Qhov yog, qhov tsav no tau teeb tsa kom pib tig thaum ib tus neeg nkag mus rau nws, thiab raug ncua tom qab sijhawm tas.

Pom tseeb, nws yuav txias kom paub tias muaj pes tsawg lub sijhawm nws hloov pauv txhua hnub. Yog li kuv tau ntxiv lwm qhov datastream rau kuv Daim Ntawv Qhia System.

Nws yog qhov nyuaj me ntsis kom tau txais cov xwm txheej ntawm HDD tsav, tab sis kuv pom txoj hauv kev! Ua ntej tshaj plaws, teeb tsa smartmontools los ntawm SSH console:

opkg hloov tshiab

opkg nruab smartmontools

Tom qab ntawd, hauv peb cov cai, peb yuav tsum tau ua cov lus txib tshwj xeeb thiab tshawb xyuas cov cai tawm:

muaj nuj nqi exec_ret (cmd)

local exit = os.execute (cmd) print ("Run:"..cmd.. " -> exit:".. exit) return exit end function getHddSpinning () if exec_ret ("smartctl --nocheck = standby --info /dev/sda>/dev/null ") == 0 ces rov 1 lwm rov qab 0 kawg kawg

Nco tseg: kuv HDD yog /dev /sda

Kauj Ruam 8: Daim Ntawv Teev Npe Network

Daim Ntawv Teev Npe Network
Daim Ntawv Teev Npe Network

Peb Tsim lwm SuperChart widget (zoo ib yam li yav dhau los), Ntxiv TX thiab RX datastreams, thiab muab rau V1 thiab V2.

Cov haujlwm pabcuam:

muaj nuj nqi getWanRxBytes ()

rov tonumber (read_file ("/sys/class/net/eth0.2/statistics/rx_bytes")) kawg ua haujlwm getWanTxBytes () rov tonumber (read_file ("/sys/class/net/eth0.2/statistics/tx_bytes")) kawg

Tom ntej no, ntxiv qee qhov chaws rau tib tmr1. Qhov no nyuaj dua, raws li peb tsuas yog xav tau los suav thiab nthuav tawm qhov sib txawv hauv kis/tau txais bytes:

local prevTx, prevRx

hauv zos tmr1 = Timer: tshiab {ntu = 5000, func = muaj nuj nqi () zos tx = getWanTxBytes () lub zos rx = getWanRxBytes () yog prevTx thiab prevTx ~ = tx ces blynk: virtualWrite (1, tx - prevTx) kawg yog prevRx thiab prevRx ~ = rx ces blynk: virtualWrite (2, rx - prevRx) kawg prevTx = tx prevRx = rx blynk: virtualWrite (5, getCpuLoad ()) blynk: virtualWrite (6, getRamUsage ()) blynk: virtualWrite (7, getHddSpinning ()) xaus}

Kauj Ruam 9: Kev ceeb toom

Kev ceeb toom
Kev ceeb toom

Kuv kuj xav kom tau txais kev ceeb toom thaum kuv Router poob lub zog lossis internet txuas rau qhov no, peb xav tau Kev ceeb toom widget.

Hauv widget teeb tsa, pab kom "ceeb toom offline". Tsis xav tau tus lej. Tab sis peb tseem tuaj yeem xa cov ntawv ceeb toom tshwj xeeb los ntawm peb cov cai.

Kauj ruam 10: Autorun hauv Tom Qab

Txog tam sim no tsab ntawv yuav tsum tau ua tiav ntawm tus kheej, tab sis kuv xav ua kom nws khiav hauv keeb kwm yav dhau los thaum lub router tau qhib.

Qhov no yog ua tiav los ntawm kev tsim cov kev pabcuam. Tsim cov ntawv /etc/init.d/blynkmon:

#!/bin/sh /etc/rc.common

START = 99 STOP = pidfile = "/var/run/blynkmon.pid" pib () {yog [-f $ pidfile]; tom qab ntawd ncha "blynkmon twb tau khiav" tawm 0 fi cd /root /lua-blynk lua blynkmon.lua koj-auth-token> /dev /null & echo $! > $ pidfile} nres () {yog [! -f $ pidfile]; ces ncha "blynkmon tsis khiav" tawm 0 fi tua -9 $ (miv $ pidfile) rm $ pidfile}

Nco tseg: tsis txhob hnov qab hloov koj li-auth-token

Tom qab ntawd, qhib kev pabcuam blynkmon:

kev pabcuam blynkmon qhib

Kauj Ruam 11: Xaus & Cov Tswv Yim Ntxiv

Xaus & Cov Tswv Yim Ntxiv
Xaus & Cov Tswv Yim Ntxiv

Koj tuaj yeem luam theej duab QR no kom tau txais qhov clone ntawm kuv li Blynk Project. Nws xav tau qee lub ntsiab lus zog (4600), vim nws siv ntau yam khoom siv!

Nrhiav Full Lua code ntawm no:

Txog tam sim no zoo heev, tab sis ntawm no yog qee cov tswv yim kuv xav ntxiv yav tom ntej.

  • Ntxiv Reboot hais kom ua. Tiv thaiv kom nyem rau nws yam tsis raug.
  • Ntxiv Terminal widget kom khiav ib qho lus txib linux.
  • Ntxiv CPU daim ntawv ntsuas kub.

    UPD: Hmoov tsis zoo OpenWrt tam sim no tsis muaj qee tus tsav tsheb rau kuv tus qauv router. Tab sis nws muaj rau ntau lwm tus routers

  • Ntxiv kev ceeb toom thaum cov cuab yeej tshwj xeeb koom nrog/tawm hauv lub network. Peb twb muaj cov ntaub ntawv arp, tam sim no tsuas yog txheeb xyuas MAC chaw nyob.

Txoj kev no, peb tuaj yeem saib xyuas thiab tswj hwm 3D Tshuab Luam Ntawv, Neeg Hlau, lub PC/Laptop ib txwm muaj, Arduino/ESP8266/ESP32/RaspberryPi khoom, Ntse Tsev Zoo, thiab txhua yam nyob ib puag ncig. Qhia rau kuv paub yog tias muaj lwm lub tswv yim nthuav. Koj xav li cas txog txhua yam no?

Pom zoo: