Author Topic: Get my external IP - the Linux way  (Read 7356 times)

0 Members and 1 Guest are viewing this topic.

Offline zWaR

  • Serf
  • *
  • Posts: 32
  • Cookies: 7
    • View Profile
Get my external IP - the Linux way
« on: December 23, 2012, 06:36:17 pm »
Hehe, It was kinda amusing reading about the windows CMD (http://evilzone.org/delphi-and-pascal/cmd-tool-to-get-external-and-local-ips/) way to show your external IP. Could not resist to post a possible linux way to do it :P

Code: [Select]
curl ip.nu

Or to get a clean output:
Code: [Select]
curl -s ip.nu | egrep '[0-9]' | awk '{print $5}'
« Last Edit: December 23, 2012, 06:40:00 pm by zWaR »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Get my external IP - the Linux way
« Reply #1 on: December 23, 2012, 08:20:40 pm »

Offline zWaR

  • Serf
  • *
  • Posts: 32
  • Cookies: 7
    • View Profile
Re: Get my external IP - the Linux way
« Reply #2 on: December 23, 2012, 08:50:59 pm »
Interesting ... (I'm not sure where to post the comment ... here or there ... but let's make it here)

Must confess the script is really ugly :P (as xzid allready mentioned)

Re the local ip, the line below is much simpler than what you suggest (works on linux, dunno for bsd and sunOS):
Code: [Select]
hostname -I

In case you have more than one ip, using cut can help to extract only one, e.g.:
Code: [Select]
# extracts the second ip
hostname -I | cut -d' ' -f2

Offline bluechill

  • Cybermancer
  • Royal Highness
  • ****
  • Posts: 682
  • Cookies: 344
  • I am the existence in these walls
    • View Profile
Re: Get my external IP - the Linux way
« Reply #3 on: January 23, 2013, 09:35:21 pm »
Interesting ... (I'm not sure where to post the comment ... here or there ... but let's make it here)

Must confess the script is really ugly :P (as xzid allready mentioned)

Re the local ip, the line below is much simpler than what you suggest (works on linux, dunno for bsd and sunOS):
Code: [Select]
hostname -I

In case you have more than one ip, using cut can help to extract only one, e.g.:
Code: [Select]
# extracts the second ip
hostname -I | cut -d' ' -f2

This does not work for people behind a router I believe.  This will get you the internal IP in that case.
I have dreamed a dream, but now that dream has gone from me.  In its place now exists my own reality, a reality which I have created for myself by myself.

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Get my external IP - the Linux way
« Reply #4 on: January 24, 2013, 04:22:49 am »
Code: [Select]
#! /bin/bash

wget -qO- icanhazip.com

Very simple.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline s3my0n

  • Knight
  • **
  • Posts: 276
  • Cookies: 58
    • View Profile
    • ::1
Easter egg in all *nix systems: E(){ E|E& };E

Offline 0poitr

  • Peasant
  • *
  • Posts: 149
  • Cookies: 64
    • View Profile
Re: Get my external IP - the Linux way
« Reply #6 on: January 24, 2013, 07:59:02 am »
wget -q -O - checkip.dyndns.org | sed -n -e 's/[^[:digit:]\|.]//g' -e 1p
Imagination is the first step towards Creation.

Offline zWaR

  • Serf
  • *
  • Posts: 32
  • Cookies: 7
    • View Profile
Re: Get my external IP - the Linux way
« Reply #7 on: January 24, 2013, 10:52:56 pm »
This does not work for people behind a router I believe.  This will get you the internal IP in that case.
True, like i said, hostname -I returns a scripting friendly internal address. The first post (among others) talks about external addr retrieval.

Offline z3ro

  • Knight
  • **
  • Posts: 345
  • Cookies: 60
    • View Profile
Re: Get my external IP - the Linux way
« Reply #8 on: January 25, 2013, 01:27:55 pm »
... hmmm.. i've always used

Code: [Select]
curl -s ifconfig.me      ;)
~ God is real. Unless declared as an integer.

Offline zWaR

  • Serf
  • *
  • Posts: 32
  • Cookies: 7
    • View Profile
Re: Get my external IP - the Linux way
« Reply #9 on: January 26, 2013, 12:14:21 am »
Hehe, there are some people in this place using linux after all, nice! Great to see all the different ideas!