Check External IP Address

Suppose we using computer that connected to the local network. We have internet access through certain gateway and the local network using NAT protocol to translate the IP address. Because it using NAT protocol, local user doesn’t know what is the external IP address that used by the gateway to access the Internet. We can use the free service on the Internet to check the current external IP address (WAN IP address). To do that we can make a simple script like this :

ttirtawi@tedy-laptop:~$ vi bin/myip 

#!/bin/bash

echo ""

echo  "Your external IP Address is:" `wget www.whatismyip.com/automation/n09230945.asp -O - -q`

echo ""

echo  "Your local IP Address is:" `ifconfig -a | grep "inet addr" | cut -d ':' -f 2 | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | grep -v 127.0.0.1`

echo ""

exit 0

ttirtawi@tedy-laptop:~$

Don’t forget to change the script’s permission to be executable.

ttirtawi@tedy-laptop:~$ chmod 770 bin/myip 

And the output of this command is like this :

ttirtawi@tedy-laptop:~$ bin/myip 

Your external IP Address is: 198.17.70.8

Your local IP Address is: 10.181.190.235

ttirtawi@tedy-laptop:~$ 

From the output we know that the local IP address is 10.181.190.235 and the external IP address is 198.17.70.8.

Other example show that the local IP address is 192.168.1.6 and the external IP address is 125.160.147.56 :

tedy@mytestbed:~$ bin/myip

Your external IP Address is: 125.160.147.56

Your local IP Address is: 192.168.1.6

tedy@mytestbed:~$

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.