Sign in to follow this  
Followers 0
frogbong

a happy couple

3 posts in this topic

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()

0

Share this post


Link to post
Share on other sites

The first script is pretty cool.

But, for the second one, it might have been easier to pull the IP from http://www.whatismyip.org

No formatting to strip

Edited by Outis
0

Share this post


Link to post
Share on other sites

wow that makes life easy, but I'm definitely glad I learned how to format output.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0