Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You need libnotify-bin and nmap
- #get_hosts_mac -- this script needs to be run as root, and put the online hosts ip and mac address in a file
- #!/bin/bash
- #Important - This script has to be run as root
- localnet=192.168.2 #Your network
- localip=192.168.2.45 #Your IP - Important, because otherwise weird stuff will happen-- If you have more ip, use a , to sepperate it
- home=/home/jim #Your home directory
- while sleep 50; do
- nmap -sP -exclude $localip $localnet.*|\
- awk '{if ($2=="scan"){printf $5 "\t"};if ($1=="MAC"){print substr($3, 0, 18)}}'>$home/hosts_online
- done
- #is_online -- this script parses the output of get_host_mac, checks for unknown mac adresses, and alert the user, does not need to be run as root
- #!/bin/bash
- >hosts_bad
- echo "Starting is_online on $(date)">>is_online.log
- while sleep 40;do
- changed=0
- while IFS=$'\t' read ip mac; do
- if ! cut -d ' ' -f2 hosts_good|grep -q $mac; then
- if ! grep -q $mac hosts_bad; then
- changed=1
- echo "$(date) | New unknown device : $(grep --color=never $mac hosts_online)">>is_online.log
- fi
- grep --color=never $mac hosts_online
- fi
- done<hosts_online>hosts_bad2
- mv -f hosts_bad2 hosts_bad
- if ((changed)); then
- notify-send -i computer "Unknown device(s) on your network:" "IP: Mac:\n$(cat hosts_bad)"
- fi
- done
- #hosts_good -- in this file you put know computer that are good -- put it in your home dir
- COMPUTER1NAME<SPACE>MAC
- COMPUTER2NAME<SPACE>MAC
- for example:
- room 00:xx:01:1E:65:E5
- fam 00:ab:01:a2:65:E3
- iPodTouch 56:59:41:A7:C4:F1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement