在检测到wifi网络时发出警报?

塔伦

当检测到wifi(无线)网络时,有什么方法可以播放声音以提醒我?

拉杜·拉迪亚努(RaduRădeanu)

问题是,据我所知,没有特定的程序/服务/守护程序来检查何时新的无线网络出现在/从无线天线的范围出现/消失(实际上有airodump-ng,也许还有其他,但这是冲突的)使用网络管理器)。

或者,您可以使用工具不时扫描wifi网络iwlist

注意: “测试中”iwlist工具仅适用于Atheros,Intel或Broadcom卡。

话虽这么说,以下脚本可以完成您想要的操作(我将其命名为wifidetect):

#!/bin/bash

#wifidetect - Alert when new wireless 

#Licensed under the standard MIT license:
#Copyright 2013 Radu Rădeanu (http://askubuntu.com/users/147044/).
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

DISPLAY=:0.0
#change 'username' with your username
HOME=/home/username/
XAUTHORITY=$HOME/.Xauthority
export DISPLAY XAUTHORITY HOME

#check if you run the script as root
if [ "$(whoami)" != "root" ]; then
    notify-send -i error "You must to run $(basename $0) script as root."
    echo "You must to run $(basename $0) script as root."
    exit
fi

#check if beep is installed
if [ ! -n "$(dpkg -s beep 2>/dev/null | grep 'Status: install ok installed')" ]; then
    notify-send -i error "The package 'beep' must to be installed before to run $(basename $0)." "Use 'sudo apt-get install beep' command in terminal to install it."
    echo -e "The package 'beep' must to be installed before to run $(basename $0)\nUse 'sudo apt-get install beep' command in terminal to install it."
    exit
fi

[ -f /tmp/networks ] || > /tmp/networks

#scan for networks - need root privileges
#change 'wlan0' with your interface name of your wireless network card; you can find it using 'ls /sys/class/net' command
sudo iwlist wlan0 scan | grep -E "Address|ESSID" |  awk 'BEGIN {FS=": |\""} {print $2}' | sed 'N;s/\n/ /' | sort > /tmp/new_networks

#check if there are new networks
new_networks=$(comm -1 -3 /tmp/networks /tmp/new_networks)
new_essids=$(echo $new_networks | sed "s/..:..:..:..:..:..//g" | sed "s/  /, /g")

if [ -n "$new_networks" ]; then   #if there are new networks
    #send a graphical notification
    notify-send -i /usr/share/app-install/icons/wifi-radar.svg "New network(s) detected:" "$new_essids"
    #send a sound notification
    pcspkr_on=$(lsmod | grep pcspkr)
    if [ -n "$pcspkr_on" ]; then 
        beep
    else 
        sudo modprobe pcspkr
        beep
        sudo modprobe -r pcspkr
    fi

    #change the old list of networks with the list containing new networks
    #the networks that were detected in the previous scan and wern't detected this time will be removed from the list
    cat /tmp/new_networks > /tmp/networks

    #if you want that only the new networks detected (who were not detected in previous scans) to be added to list, comment the previous line and and uncomment the following three
    #cat /tmp/networks > /tmp/tmp_networks
    #cat /tmp/new_networks >> /tmp/tmp_networks
    #cat /tmp/tmp_networks | sort | uniq > /tmp/networks
fi

注意:您必须username使用您的用户名和wlan0无线网卡的接口名称更改脚本您可以使用“ ls / sys / class / net”命令找到它。

不要忘记在终端中使用以下命令使脚本可执行:

chmod +x /path/to/scripts/wifidetect

最后,sudo crontab -e通过添加以下行,使用命令编辑root的crontab条目

*/1 * * * * /path/to/scripts/wifidetect

我已经为每分钟设置了Cron工作,但是您可以根据自己的意愿或认为更好的方式进行更改。在这种意义上,请参见http://en.wikipedia.org/wiki/Cron

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在检测到wifi网络时发出警报?

来自分类Dev

检测到活动后发出警报

来自分类Dev

发出警报消息时的呼叫功能

来自分类Dev

存储过程失败时发出警报

来自分类Dev

开始闪亮时发出警报消息

来自分类Dev

Windows启动时发出警报

来自分类Dev

脚本加载时发出警报

来自分类Dev

在循环javascript时发出警报

来自分类Dev

存储过程失败时发出警报

来自分类Dev

到达页面底部时发出警报,当我到达页面顶部时发出警报

来自分类Dev

未检测到特定 WiFi 网络

来自分类Dev

大写锁定打开时发出警报的软件

来自分类Dev

javascript失败时是否发出警报Javascript错误?

来自分类Dev

运行过程结束时发出警报

来自分类Dev

验证规则,当字段不为空时发出警报

来自分类Dev

单击禁用按钮时发出警报窗口

来自分类Dev

Scapy:发现已知源IP时发出警报

来自分类Dev

大写锁定打开时发出警报的软件

来自分类Dev

运行过程结束时发出警报

来自分类Dev

错误提示启动时发出警报

来自分类Dev

在jQuery无法获取ip地址时发出警报。

来自分类Dev

输入大于或小于16位时发出警报消息

来自分类Dev

出现数学问题时发出警报

来自分类Dev

我想在 nodejs 中删除文件时发出警报

来自分类Dev

当输入范围更改为特定值时发出警报

来自分类Dev

未检测到互联网时自动连接到wifi网络

来自分类Dev

仅在检测到某些Wifi网络时才允许签入

来自分类Dev

根据“ if”语句发出警报

来自分类Dev

用Java发出警报