Search This Blog

Monday, March 30, 2009

script to get the external IP address

When a machine sits behind a router, it has two IP addresses. One internal (assigned by the router), one external (assigned by the ISP). To find the external IP address of the machine, I use the following script called ip.
$cat ip
#! /bin/sh

# get the external IP address of the machine
# Author : Kamraju Kusumanchi
# Date : Mon Mar 30 00:08:11 EDT 2009

curl www.whatismyip.org
echo ""
On my machine, I have
$curl --version
curl 7.18.2 (i486-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/0.6.5 libssh2/0.18
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
Execution
$which ip
/home/rajulocal/bin/ip

$ip
141.153.242.115

Followers