EvilZone
Programming and Scripting => Other => : 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}'
-
Well I had made a tool for that too:
http://evilzone.org/scripting-languages/terminal-tool-to-get-external-and-local-ips/
-
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
-
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.
-
#! /bin/bash
wget -qO- icanhazip.com
Very simple.
-
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
-
wget -q -O - checkip.dyndns.org | sed -n -e 's/[^[:digit:]\|.]//g' -e 1p
-
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.
-
... hmmm.. i've always used
curl -s ifconfig.me
;)
-
Hehe, there are some people in this place using linux after all, nice! Great to see all the different ideas!