If your computer accesses the Internet via a local network connection, it will have an internal (LAN / WiFi) as well as an external (Internet) IP Address. If you need to reference either of these on a Unix machine, you can do so relatively easily from the command line.

Checking your internal IP address:

To check the IP Address of your LAN / WiFi connection, ensure that Perl is installed, then run this command on the command line:

ifconfig | perl -nle '/inet [addr:]*(\S+)/ && print $1'

Explanation:

ifconfig” will output your computer’s network interface parameters. These results will be piped into a Perl script with “perl -nle” running the specified line of code with line ending processing enabled and assuming a “while (<>) { … }” loop around the code. The “/inet [addr:]*(\S+)/ && print $1” line of code will output the IP Address section of the result of a regular expression search for lines containing “inet ” followed by an optional “addr:“.

Checking your external IP address:

To check the address of your Internet connection, ensure that cURL is installed, then run this command on the command line:

curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g'

Explanation:

curl -s http://checkip.dyndns.org” will fetch the source of the specified URL without displaying a progress meter or error messages. This result will be piped into sed, and “sed ’s/[a-zA-Z/<> :]//g’” will replace all alphabetic characters, forward slashes, lesser than, greater than, space and colon characters with (nothing) globally (throughout the entire input, not just up to the first instance).

For more information on perl, curl and sed, use these commands:

man perl
man curl
man sed
perl --help
curl --help
sed --help
Share this article: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Twitter
  • GatorPeeps
  • Digg
  • Reddit
  • muti.co.za
  • DZone
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Ma.gnolia
  • Slashdot

Related posts:

  1. Checking which processes are accessing the Internet on a Unix machine
  2. Testing SMTP servers from a UNIX command line
  3. UNIX Quick Tip: See the current UNIX Timestamp and other date formats on the command line
  4. A Python script to check Google rankings for a specific domain and search term
  5. Checking directory sizes on a Bash command line