This forum is in archive mode. You will not be able to post new content.

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

0 Members and 2 Guests 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!

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.