使用wireshark抓包 可以得知 一些网络摄像头通过定时广播包通告其局域网地址的
广播包可以使用 nc netcat接收内容
组播包可以使用 nmc 接收
以某摄像头为例 周期性向 5001 广播
防火墙开启接收广播
#broadcast
iptables -t filter -A INPUT -m addrtype --dst-type BROADCAST -j ACCEPT
netcat有多个版本,使用的是 netcat-openbsd
接收通告地址
nc -u -p 5001 -l -b -W 1|grep --text -o -E “http://[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}”
例 放入crontab检测
[ $(/usr/bin/curl -sIL -w “%{http_code}\n” -o /dev/null $(/usr/bin/nc -u -p 5001 -l -b -W 1 |/usr/bin/grep --text -o -E “http://[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}”)) -eq 200 ] && echo “ok”
#!/bin/sh
PORT=5001
timeout -s 9 60s /usr/bin/nc -u -p $PORT -l -b -W 1 >/dev/null
#timeou返回值 0 =不超时 ; 不为0超时
if [ $? -eq 0 ]; then
[ $(/usr/bin/curl -sIL -w "%{http_code}\n" -o /dev/null $(/usr/bin/nc -u -p 5001 -l -b -W 1 |/usr/bin/grep --text -o -E "http:\/\/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}")) -eq 200 ] && paplay --playback --client-name="camera-warnning" --volume-32768 --device=@DEFAULT_SINK@ ~/warnning.ogg
exit 0
fi