I found these useful, I hope you do as well. Making these helped me learn some basic but useful things about bash, linux and python.
#!/bin/bash
##
### netmon.sh - use nmap to watch local network for active hosts
## Note: don't forget to set 'NETWORK' to your subnet
#
export NETWORK="10.0.1."
# Cleanup
function cancel() {
echo ""
echo "deleting /tmp/netmon.tmp.."; rm -f /tmp/netmon.tmp
echo "killing all instances of nmap.."; killall -g nmap
echo "killing all instances of netmon.sh.."; killall -g netmon.sh
}
# Make sure to catch ctrl-c for cleanup routine
trap cancel SIGINT
# Check if nmap is installed
if [ -f `which nmap` ]
then
touch /tmp/netmon.tmp
while true; do nmap -sP $NETWORK*|grep $NETWORK > /tmp/netmon.tmp; sleep 30; done &
while true; do clear; echo "Local Network: "; cat /tmp/netmon.tmp; sleep 7; done
else
# If nmap is not installed tell the user and quit
echo "nmap not found: install nmap and run again" && exit
fi
#!/usr/bin/python
##
### getip.py - get external ip from ipchicken.com
##
#
import httplib
conn = httplib.HTTPConnection("ipchicken.com")
conn.request("GET", "/")
resp = conn.getresponse()
if resp.status != 200:
print resp.status, resp.reason
exit()
elif resp.status == 200:
output = resp.read()
output = output[output.find('<font face="Verdana, Arial, Helvetica, sans-serif" size="5" color="#0000FF"><b>'):
output.find('<A HREF="javascript:makeLink()"><font size="2">')]
output = output.strip('font face="Verdana, Arial, Helvetica, sans-serif" size="5" color="#0000FF"><b>')
output = output.strip()
output = output.strip('<br>')
print output
else:
print resp.status, resp.reason
exit()