V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zgzh
V2EX  ›  Bash

利用 openwrt 路由器+树莓派+bash 脚本实时发现隔壁老王来访并发送邮件+短信通知,隔壁老王连上我路由器可以发现并收到通知,一直在发送,根本停不下来,求消停的方法

  •  
  •   zgzh · 2016-12-30 11:45:58 +08:00 · 1721 次点击
    这是一个创建于 2646 天前的主题,其中的信息可能已经有所发展或是发生改变。

    根据原文地址: http://blog.csdn.net/c80486/article/details/43503301

    作者原文中有说到:如果一个手机持续连接 WIFI ,则每次查找时均可找到它,如果不断发短信是很烦人的,所以程序中采用了一个变量 last_time 记录上一次找到 MAC 码的时间,如果是连续找到,则不会触发网页。 但是目前的实际情况是每分钟就发一个短信,根本停不下来,求消停的方法,比如发送 2 次后停止发送。代码如下

    #!/bin/sh
    MAC="E0:19:1D:E4:22:25"
    URL="http://192.168.31.131/wifi/find.php?mac="

    #check duration, in seconds
    interval=2

    #To avoid notify continously, last_time is the last time we find the MAC
    last_time=$(date +%y%m%d%H%M%S)
    let last_time=last_time-interval-interval

    #Function: Find MAC address in associated users , query the url while matched. return 1 if found, return 0 if not found
    find_mac() {
    #Use ifconfig to find interface which name starts with wl
    ifconfig | grep wl[0-9] | awk '{print $1}' | while read WLAN
    do
    #Use iwinfo to find MAC address of connected users
    iwinfo $WLAN assoclist | grep dBm | awk '{print $1}' | while read MAC1
    do
    #if MAC1 address is the target we want
    if [ $MAC1 = $MAC ]
    then
    #Calculate time passed since last_time
    this_time=$(date +%y%m%d%H%M%S)
    let time_passed=this_time-last_time
    let interval_min=interval+1
    if [ $time_passed -gt $interval_min ]
    then
    #construct the url , append the MAC address to the end
    QUREY_URL="${URL}${MAC}"
    #Use wget to query the url
    wget -q -O web_response $QUREY_URL
    echo "FIND $MAC"
    return 1
    fi
    fi
    done
    done
    return 0
    }

    #Main program: it's a dead loop, exec find_mac() every n seconds(defined by interval)
    while [ 1 -lt 2 ]
    do
    if find_mac
    then
    #if found, update last_time
    last_time=$(date +%y%m%d%H%M%S)
    fi
    sleep $interval
    done

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2427 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:00 · PVG 00:00 · LAX 09:00 · JFK 12:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.