Advertisement
Guest User

Jim Bauwens

a guest
Nov 26th, 2010
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.56 KB | None | 0 0
  1. You need libnotify-bin and nmap
  2.  
  3. #get_hosts_mac -- this script needs to be run as root, and put the online hosts ip and mac address in a file
  4.  
  5. #!/bin/bash
  6.  
  7. #Important - This script has to be run as root
  8.  
  9. localnet=192.168.2     #Your network
  10. localip=192.168.2.45   #Your IP - Important, because otherwise weird stuff will happen-- If you have more ip, use a , to sepperate it
  11. home=/home/jim         #Your home directory
  12.  
  13. while sleep 50; do
  14.     nmap -sP -exclude $localip $localnet.*|\
  15.     awk '{if ($2=="scan"){printf $5 "\t"};if ($1=="MAC"){print substr($3, 0, 18)}}'>$home/hosts_online
  16. done
  17.  
  18. #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
  19.  
  20. #!/bin/bash
  21.  
  22. >hosts_bad
  23. echo "Starting is_online on $(date)">>is_online.log
  24.  
  25. while sleep 40;do
  26.     changed=0
  27.     while IFS=$'\t' read ip mac; do
  28.         if ! cut -d ' ' -f2 hosts_good|grep -q $mac; then
  29.             if ! grep -q $mac hosts_bad; then
  30.                 changed=1
  31.                 echo "$(date) | New unknown device : $(grep --color=never $mac hosts_online)">>is_online.log
  32.             fi
  33.             grep --color=never $mac hosts_online
  34.         fi
  35.     done<hosts_online>hosts_bad2
  36.  
  37.     mv -f hosts_bad2 hosts_bad
  38.     if  ((changed)); then
  39.         notify-send -i computer "Unknown device(s) on your network:" "IP:              Mac:\n$(cat hosts_bad)"
  40.     fi
  41. done
  42.  
  43.  
  44. #hosts_good -- in this file you put know computer that are good -- put it in your home dir
  45.  
  46. COMPUTER1NAME<SPACE>MAC
  47. COMPUTER2NAME<SPACE>MAC
  48.  
  49. for example:
  50.  
  51. room 00:xx:01:1E:65:E5
  52. fam 00:ab:01:a2:65:E3
  53. iPodTouch 56:59:41:A7:C4:F1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement