Pages

Monday, January 3, 2011

How to detect your IP Address in Linux ?

The following shell script requires Internet Connection

wget http://www.whatismyip.com/automation/n09230945.asp -O /tmp/ip.txt -o /dev/null
 
Reference: 
http://www.cyberciti.biz/faq/bash-shell-command-to-find-get-ip-address/


To get IP Address alone (by pattern maching):
This script will give your IP Address  (LAN Address).
The pre-requisite is , interface eth0 needs to be up

ipaddress=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'` 



Use of the following expression is also suggested.

ifconfig eth0 | sed '/inet\ /!d;s/.*r://g;s/\ .*//g'

No comments:

Post a Comment