Ivor O’Connor

January 18, 2010

Getting your IP address

Filed under: Uncategorized — ioconnor @ 3:36 am

Linux Journal has an article I like at http://www.linuxjournal.com/content/tech-tip-getting-your-mac-and-ip-address-script

Ever wanted to get the MAC or IP address of your computer in a Linux shell script? The following two commands should work on most flavours of Linux/Unix.

To get your IP address:

/sbin/ifconfig \
| grep ‘\’ \
| sed -n ‘1p’ \
| tr -s ‘ ‘ \
| cut -d ‘ ‘ -f3 \
| cut -d ‘:’ -f2
To get your MAC address (Hardware address):

/sbin/ifconfig \
| grep ‘eth0’ \
| tr -s ‘ ‘ \
| cut -d ‘ ‘ -f5
Note that this retrieves the address of the eth0 interface by default.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: