notify new online/offline devices in network [raspberrypi]

maybe try instead my new project:
https://github.com/freddii/presence-detector-pi

scan_network:
This script was not very relyable working for me.
It requires to setup pushbullet first.

install nmap:
sudo apt-get install nmap -y

create the script:
cd
touch ~/scan_network.sh
chmod +x ~/scan_network.sh
nano ~/scan_network.sh

#!/bin/bash

API="your api" #add your api here

IDEN="your device iden" #add your iden here

#based on https://askubuntu.com/questions/398321/notification-when-someone-connects-to-my-local-network-arp-notification-file
#Script to monitor the network and put changes to notification

#Save previous scan
cp scan.txt previousscan.txt
#get numeric list of online hosts
nmap -n -sn 192.168.1.0-36 > scan.txt
#collect the difference, only the lines with ip-numbers
message=$(diff previousscan.txt scan.txt | grep 192)
#get first char which indicates if the host came up or went away
iostring="${message:0:1}"
#get first ip-number from the list
computer="${message:23:17}"

#show ip-number in notify if host came up
if [ "$iostring" = \> ]; then
        echo "$computer online"
        curl -u $API: https://api.pushbullet.com/v2/pushes -d device_iden="$IDEN" -d type=note -d title="Alert" -d body="$computer online"
        fi
#show ip-number in notify if host went away
if [ "$iostring" = \< ]; then
        echo "$computer offline"
        curl -u $API: https://api.pushbullet.com/v2/pushes -d device_iden="$IDEN" -d type=note -d title="Alert" -d body="$computer offline"
        fi

run it once a minute:
crontab -e

*/1 * * * * /home/pi/scan_network.sh

wifinder:
install python-nmap:
sudo apt-get install python-nmap -y

create a directory:
cd
mkdir wifinder
cd ./wifinder/

get the script:
wget https://raw.githubusercontent.com/mpescimoro/wi-finder/master/wifinder.py
chmod +x wifinder.py

to run the script:
sudo python /home/pi/wifinder/wifinder.py

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s