Author Topic: unix like shell ways to get your external IP  (Read 941 times)

0 Members and 1 Guest are viewing this topic.

Offline v32itas

  • Peasant
  • *
  • Posts: 123
  • Cookies: -4
  • coup de grâce
    • View Profile
unix like shell ways to get your external IP
« on: 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.
Code: [Select]
wget -qO- http://icanhazip.com

Another way found in another forum, but even more simple.

Code: [Select]
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 )
Code: [Select]
ip a | grep "eth0" -A 2 | grep "inet" | cut -d " " -f 6 | cut -d / -f 1In 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.

Code: [Select]
ip a | fgrep "eth0" -A 2 | fgrep "inet" | cut -d " " -f 6 | cut -d / -f 1
« Last Edit: October 05, 2015, 06:15:44 pm by v32itas »
"There is nothing more deceptive then an obvious fact." - SH

“There was no such thing as a fair fight. All vulnerabilities must be exploited.”
― Cary Caffrey





Offline gray-fox

  • Knight
  • **
  • Posts: 208
  • Cookies: 52
    • View Profile
Re: unix like shell ways to get your external IP
« Reply #1 on: October 05, 2015, 08:05:35 am »
Code: [Select]
dig +short myip.opendns.com @resolver1.opendns.com

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: unix like shell ways to get your external IP
« Reply #2 on: October 05, 2015, 08:08:17 am »
Code: [Select]
wget -qO- http://icanhazip.com
Code: [Select]
curl icanhazip.com
Is much shorter ;)
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline gray-fox

  • Knight
  • **
  • Posts: 208
  • Cookies: 52
    • View Profile
Re: unix like shell ways to get your external IP
« Reply #3 on: October 05, 2015, 08:47:29 am »
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,
Code: [Select]
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.

Offline v32itas

  • Peasant
  • *
  • Posts: 123
  • Cookies: -4
  • coup de grâce
    • View Profile
Re: unix like shell ways to get your external IP
« Reply #4 on: October 05, 2015, 02:01:58 pm »
Code: [Select]
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 :

Code: [Select]
lynx -dump myip.alienbase.nl
and additional suggestion by jeaye from slackware community using curl but different domain

Code: [Select]
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.
« Last Edit: October 05, 2015, 02:32:45 pm by v32itas »
"There is nothing more deceptive then an obvious fact." - SH

“There was no such thing as a fair fight. All vulnerabilities must be exploited.”
― Cary Caffrey





Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: unix like shell ways to get your external IP
« Reply #5 on: October 05, 2015, 04:08:18 pm »
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 :

Code: [Select]
lynx -dump myip.alienbase.nl
and additional suggestion by jeaye from slackware community using curl but different domain

Code: [Select]
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.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline v32itas

  • Peasant
  • *
  • Posts: 123
  • Cookies: -4
  • coup de grâce
    • View Profile
Re: unix like shell ways to get your external IP
« Reply #6 on: October 11, 2015, 06:32:24 am »
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.
"There is nothing more deceptive then an obvious fact." - SH

“There was no such thing as a fair fight. All vulnerabilities must be exploited.”
― Cary Caffrey