EvilZone
General Tech => Operating System => : v32itas October 05, 2015, 04:57:09 AM
-
Two very nice ways with different tools to get your external IP on unix-like systems, not dependent on shell you use.
This one I found on this forum, but extracted from whole topic just this useful part of it.
wget -qO- http://icanhazip.com
Another way found in another forum, but even more simple.
curl ifconfig.me
These two ways should be universal on all unix-like systems linux, bsd, os x, solaris .... They're just dependent on tools and external web servers. Another way I founf that is independent on external web server, but only works on some linux VPS( depends on VPS provider networking )
Only for some linux VPS ( usefull in shell scripts )
ip a | grep "eth0" -A 2 | grep "inet" | cut -d " " -f 6 | cut -d / -f 1
In most normal cases this just gets your lan eth0 ip. Just this trick for extracting IP itself from ip a output might be handy for someone interested in shell scripting.
NOTE: I suggest everyone that still uses ifconfig on linux to switch to ip and iw from iwconfig and ifconfig. Because iwconfig and ifconfig is deprecated and no longer evolving in linux. Ifconfig is godlike in BSD but only iw and ip has a future on linux.
Please add more ways to get external IP on unix like shell. I would like to see them. And this can be useful to someone later.
EDIT: ==========================
Just discovered quicker way for that greping of ip output so I think it would be apropriate to update it. So faster way is to replace grep with fgrep it might improve it's speed by few miliseconds or so. But still it is important to notice that sometimes might be better to use fgrep instead of grep.
ip a | fgrep "eth0" -A 2 | fgrep "inet" | cut -d " " -f 6 | cut -d / -f 1
-
dig +short myip.opendns.com @resolver1.opendns.com
-
wget -qO- http://icanhazip.com
curl icanhazip.com
Is much shorter ;)
-
That reminded me, I have many times preferred curl ifconfig.me because it's short and because of the "ifconfig" it's easy to remember but its response time is usually intolerable slow. That's why I now usually just add,
alias wip="dig +short myip.opendns.com @resolver1.opendns.com"
to .bashrc so I can get ext Ip just with "wip" command.
I know, reqular stuff for most of you, but someone might find this info useful.
-
dig +short myip.opendns.com @resolver1.opendns.com
Very nice suggestion with dig, thank you. And yes curl ifconfig.me is seriously slow.
need to add another way suggested by alienBOB from slackware community, slackware has lynx included in full install :
lynx -dump myip.alienbase.nl
and additional suggestion by jeaye from slackware community using curl but different domain
curl ipecho.net/plain
please add more known ways to do this if you know, I would like to see as much ways for this as possible.
-
Very nice suggestion with dig, thank you. And yes curl ifconfig.me is seriously slow.
need to add another way suggested by alienBOB from slackware community, slackware has lynx included in full install :
lynx -dump myip.alienbase.nl
and additional suggestion by jeaye from slackware community using curl but different domain
curl ipecho.net/plain
please add more known ways to do this if you know, I would like to see as much ways for this as possible.
On windows 8/2012 server you can just do 'curl'/'wget' since these come packed.
-
On windows 8/2012 server you can just do 'curl'/'wget' since these come packed.
Very interesting. But I have no windows available here I got rid of it all. Maybe you can explain it in little bit more detail here or Maybe windows would be worth separate thread on this. Do curl and wget work same as on unix-like systems there? I'm not using it currently but I'm very interested in windows shell too.
##############################################
Reposting because of edit, just to say that I made same lesson for lithuanian programisiai community. Giving all appropriate credit for all of your awesome suggestions.
https://programisiai.lt/index.php/topic,1826.0.html nicknames in bold
P.S. I'm not responsible for current forum desing blame Kulverstukas or Simba. They are administrators there. Nah just joking, everything is working fine there currently just in progress starting something.