commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Instead of hard-coding in a check to scrape info from ifconfig based on a specific interface, do it in a more portable way.
This works really well if you switch between wired, wireless, bluetooth or even VPN connections. You can get your current IP in a script (since it'll be something like tun0 instead of eth0 or wlan1).
This uses a well known public ip address 220.127.116.11, but it doesn't actually connect to it, it just shows you the route it would take.
A shorter version
Just a simple way without the need of additional tools. Of course, replace eth0 with your IF.