EvilZone

Programming and Scripting => Other => : zWaR December 23, 2012, 06:36:17 PM

: Get my external IP - the Linux way
: zWaR 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

:
curl ip.nu

Or to get a clean output:
:
curl -s ip.nu | egrep '[0-9]' | awk '{print $5}'
: Re: Get my external IP - the Linux way
: Kulverstukas December 23, 2012, 08:20:40 PM
Well I had made a tool for that too:
http://evilzone.org/scripting-languages/terminal-tool-to-get-external-and-local-ips/
: Re: Get my external IP - the Linux way
: zWaR 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):
:
hostname -I

In case you have more than one ip, using cut can help to extract only one, e.g.:
:
# extracts the second ip
hostname -I | cut -d' ' -f2
: Re: Get my external IP - the Linux way
: bluechill 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):
:
hostname -I

In case you have more than one ip, using cut can help to extract only one, e.g.:
:
# 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.
: Re: Get my external IP - the Linux way
: proxx January 24, 2013, 04:22:49 AM
:
#! /bin/bash

wget -qO- icanhazip.com

Very simple.
: Re: Get my external IP - the Linux way
: s3my0n January 24, 2013, 06:30:36 AM
I did this kinda thing in python a while ago: https://forum.intern0t.org/hacking-tools-utilities/4050-getmyip-get-your-ip-address-command-line-extra-options.html
: Re: Get my external IP - the Linux way
: 0poitr January 24, 2013, 07:59:02 AM
wget -q -O - checkip.dyndns.org | sed -n -e 's/[^[:digit:]\|.]//g' -e 1p
: Re: Get my external IP - the Linux way
: zWaR 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.
: Re: Get my external IP - the Linux way
: z3ro January 25, 2013, 01:27:55 PM
... hmmm.. i've always used

:
curl -s ifconfig.me      ;)
: Re: Get my external IP - the Linux way
: zWaR 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!