The world is my backyard.
Random header image... Refresh for more!

One command to rule…. alright, just return an IP

One of my friends who is into networks always joke, as why there is no single Unix command to return only the IP address and nothing else. Here is a script that just does that one thing and nothing else.

#!/usr/bin/env bash # Arvinder Singh Kang # askang@olemiss.edu # Version 0.1 - 2009-06-02 # ipaddress: This snippet returns the ipaddress of the current computer. Store in a directory which is in the PATH, and make it executable by running "chmod +x ipaddress". # Running command ipaddress should return ipaddresses of this machine.

ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'

2 comments

1 Baljitpal Singh { 01.01.10 at 3:24 pm }

Hello Kang Paaji,

Looks like something is missing…i mean…i think….it should be IPCONFIG, in place of IFCONFIG… I am not sure….

Regards Baljit

2 Arvinder Kang { 01.04.10 at 11:29 am }

Baljit,

The equivalent command for Windows’ ipconfig command in Unix/Linux is ifconfig

Leave a Comment