#!/bin/sh # POSIX SH shell script to display the IP Address - one that the machine has, # as well as router's public IP Address, if any. # First written : S Gowtham, Wed Dec 28 22:05:35 EST 2005 # Last modified : S Gowtham, Fri Dec 30 06:57:50 EST 2005 # S Gowtham, Tue Jan 3 09:52:47 EST 2006 # Jon DeVree, Tue Jan 3 22:28:15 EST 2006 # (jadevreeNOSPAM@mtu.edu) # Questions/Comments must be sent to mail@sgowtham.net IFACE=`netstat -rn | grep ^0.0.0.0 | awk '{print $8}'` if [ "$IFACE" = "" ]; then echo echo " You are not connected to the internet" echo exit 0 fi IP=`/sbin/ifconfig $IFACE | grep Bcast | awk '{print $2}' | awk -F ':' '{print $2}'` NSIP=`curl -s http://checkip.dyndns.org | awk '{print $6}' | awk -F '<' '{print $1}'` if [ "$IP" = "$NSIP" ]; then echo echo " Your machine is directly connected to the internet" echo " IP Address : $IP" echo else echo echo " Your machine is configured behind a router" echo " Machine's static IP Address : $IP" echo " Router's public IP Address : $NSIP" echo fi