ADAMPOKE111
Posts: 62
Joined: Wed Mar 07, 2012 6:38 pm

Public/External IP

Mon Nov 19, 2012 8:38 pm

:? How do you find out your public/external IP (the one that people would use to connect to your lighttpd webserver lol!)?

ADAMPOKE111
Posts: 62
Joined: Wed Mar 07, 2012 6:38 pm

Re: Public/External IP

Mon Nov 19, 2012 8:39 pm

:roll: Oh... I forgot to mention I want to find it out from the Terminal.

User avatar
azeam
Posts: 194
Joined: Fri Oct 26, 2012 11:13 pm
Contact: Website

Re: Public/External IP

Mon Nov 19, 2012 9:45 pm

http://www.whatsmyip.org/ or from the terminal:

Code: Select all

curl ifconfig.me

User avatar
hop
Posts: 87
Joined: Thu Nov 22, 2012 9:40 pm

Re: Public/External IP

Fri Nov 23, 2012 7:30 am

You can use ifconfig to find details about your IP.

iainmaoileoin
Posts: 16
Joined: Tue Jul 31, 2012 10:57 pm

Re: Public/External IP

Fri Nov 23, 2012 8:18 am

ifconfig will tell you lots about your LOCAL system network, but unless you are the final hop to the internet it may not tell you enough.

whatismyip.com works fine - but in complex networks the http traffic can be squidded/cached and whatismyip will give you address of the cache-server which may be different from the actual address used.

Further note that if you are on a "NAT"ed connections - behind a router or a firewall - the address of your own system will not be relevant, it is the address of the last hop router. Even if you find the address of that router it may not allow traffic back to your pi.
Under such cases it may be difficult to find the external IP from the keyboard. I say again your firewall may not allow connections back to your system.

Code: Select all

[email protected]:~/gpio# ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:17:e9:ae  
          inet addr:192.168.0.99  Bcast:192.168.0.255  Mask:255.255.255.0
Traceroute might help? In the list below I (192.168.0.99) send my packets to a gateway router on 192.168.0.254 to be forwarded to the internet. The hops following (shown as stars) mean that the router/firewall will not reveal any addresses, so I cant see my external address from that source. You might.

Code: Select all

[email protected]:~/gpio# traceroute -n bbc.co.uk
traceroute to bbc.co.uk (212.58.241.131), 30 hops max, 60 byte packets
 1  192.168.0.254  0.540 ms  0.439 ms  0.461 ms
 2  * * *
 3  * * *
 4  10.130.130.163  905.224 ms  945.677 ms  984.402 ms
 5  * * *
 6  192.168.34.10  1075.704 ms  1121.034 ms  1159.816 ms
 7  10.130.2.45  1190.702 ms  769.597 ms  780.492 ms
 8  10.130.1.18  811.575 ms  729.678 ms  708.844 ms
 9  195.81.51.225  710.000 ms  720.432 ms  720.336 ms
10  89.202.255.217  708.984 ms  747.323 ms 212.23.42.25  768.647 ms
11  80.81.192.59  730.834 ms  730.039 ms  728.703 ms
12  212.58.239.217  740.345 ms 84.233.218.185  729.092 ms  740.623 ms
13  84.233.218.189  758.915 ms * *
14  84.233.186.74  760.108 ms 132.185.254.46  759.950 ms  770.348 ms
15  * 132.185.255.60  730.504 ms  729.106 ms
16  212.58.241.131  758.610 ms 132.185.254.46  748.844 ms 212.58.241.131  759.693 ms
Also note that some connections (cable and satellite at least) have dhcp type allocation of your public IP address, and it can change. Why do you want the address, there may be another way to get it.

Tell us more about your setup and we can help a bit more.

User avatar
RaTTuS
Posts: 10377
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Public/External IP

Fri Nov 23, 2012 8:39 am

curl www.wieistmeineip.de | awk '(/[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]/) {print}' | awk 'gsub(/[>||<]/," ")' | awk '{print $3}'
will show the public bit
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

ghans
Posts: 7868
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Public/External IP

Fri Nov 23, 2012 12:56 pm

I'm using traceroute too for this too. A perl script gets my public
IP from the output in a horribly inefficient way and then uploads it to
a server.


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
hop
Posts: 87
Joined: Thu Nov 22, 2012 9:40 pm

Re: Public/External IP

Fri Nov 23, 2012 9:55 pm

You gotta love Perl though, it manages to make the simplest things look the ugliest. :lol:

timbresnan
Posts: 1
Joined: Mon Mar 04, 2013 12:28 pm

Re: Public/External IP

Mon Mar 04, 2013 12:36 pm

ADAMPOKE111 wrote::? How do you find out your public/external IP (the one that people would use to connect to your lighttpd webserver lol!)?
To know your Public (or) External IP address, visit IP-details.com . This site provides you information about your Internet Service Provider, IP location, Map and Country etc..

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Public/External IP

Tue Mar 05, 2013 9:04 pm

If your router has telnet access you may be able to derive the IP address from your local network.
Mileage will vary according to your ISP; O2 have a telnet interface, BT don't.

paracha3
Posts: 2
Joined: Thu Oct 17, 2013 11:16 am

Re: Public/External IP

Thu Oct 17, 2013 11:18 am

Forget perl. Just one line.

Code: Select all

curl http://ipecho.net/plain

User avatar
IgorGanapolsky
Posts: 33
Joined: Sun Apr 10, 2016 8:32 pm

Re: Public/External IP

Sun Jun 19, 2016 9:06 pm

azeam wrote:http://www.whatsmyip.org/ or from the terminal:

Code: Select all

curl ifconfig.me
What is ifconfig.me? Where do you get this file.

User avatar
DougieLawson
Posts: 35536
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Public/External IP

Sun Jun 19, 2016 9:14 pm

IgorGanapolsky wrote:
azeam wrote:http://www.whatsmyip.org/ or from the terminal:

Code: Select all

curl ifconfig.me
What is ifconfig.me? Where do you get this file.

Code: Select all

[email protected]:/tmp$ curl http://ifconfig.me/
xxx.xxx.205.233
[email protected]:/tmp$
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
azeam
Posts: 194
Joined: Fri Oct 26, 2012 11:13 pm
Contact: Website

Re: Public/External IP

Sun Jun 19, 2016 9:17 pm

IgorGanapolsky wrote:
azeam wrote:http://www.whatsmyip.org/ or from the terminal:

Code: Select all

curl ifconfig.me
What is ifconfig.me? Where do you get this file.
It's not a file, it's a url http://ifconfig.me/

User avatar
Cancelor
Posts: 757
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: Public/External IP

Mon Jun 20, 2016 9:19 am

azeam wrote:http://www.whatsmyip.org/ or from the terminal:

Code: Select all

curl ifconfig.me
+1
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Public/External IP

Mon Jun 20, 2016 9:40 am

There's also

Code: Select all

curl icanhazip.com
which does the same thing (and there are some other tools they provide http://bit.ly/icanhazip-faq)

User avatar
IgorGanapolsky
Posts: 33
Joined: Sun Apr 10, 2016 8:32 pm

Re: Public/External IP

Tue Sep 13, 2016 5:37 pm

azeam wrote:
IgorGanapolsky wrote:
azeam wrote:http://www.whatsmyip.org/ or from the terminal:

Code: Select all

curl ifconfig.me
What is ifconfig.me? Where do you get this file.
It's not a file, it's a url http://ifconfig.me/
But it's not even reachable!

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Public/External IP

Tue Sep 13, 2016 5:59 pm

IgorGanapolsky wrote:
azeam wrote:http://www.whatsmyip.org/ or from the terminal:

Code: Select all

curl ifconfig.me
But it's not even reachable!
In that case try one of the others that's been posted in this thread. Or wait and see if it comes back up.

User avatar
DougieLawson
Posts: 35536
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Public/External IP

Tue Sep 13, 2016 8:04 pm

curl http://httpbin.org/ip

Or this python3 program

Code: Select all

#!/usr/bin/python3

from urllib.request import urlopen
import json
ip = urlopen('http://httpbin.org/ip').read()
ip = ip.decode('utf-8')
ip = json.loads(ip)

print(ip['origin'])
import socket
name, alias, addresslist = socket.gethostbyaddr(ip['origin'])
print (name)
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

kahlenberg
Posts: 40
Joined: Mon Jul 29, 2013 10:47 am

Re: Public/External IP

Fri Mar 31, 2017 10:21 pm

What if we want to get public IP address only from existing command line tool like nmap or traceroute. Because the above given services like ifconfig.me might be down or unaccessible. I was using checkip.dyndns.org, it seems to be not working every time.
How can we get ip address from traceroute for example without depending on external services?

User avatar
rpdom
Posts: 14720
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Public/External IP

Sat Apr 01, 2017 8:30 am

kahlenberg wrote:What if we want to get public IP address only from existing command line tool like nmap or traceroute. Because the above given services like ifconfig.me might be down or unaccessible. I was using checkip.dyndns.org, it seems to be not working every time.
How can we get ip address from traceroute for example without depending on external services?
You can't.

Your best bet is to try more than one external service. If none of them work, then you connection is probably down and you won't have an external address anyway.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Public/External IP

Sat Apr 01, 2017 8:51 am

kahlenberg wrote:What if we want to get public IP address only from existing command line tool like nmap or traceroute. Because the above given services like ifconfig.me might be down or unaccessible. I was using checkip.dyndns.org, it seems to be not working every time.
How can we get ip address from traceroute for example without depending on external services?
There's not going to be a single way to do that. On some of my systems I can just do a simple ifconfig (or ip a) to get the public IP. On others I'd need to query the router (and that will depend on the type of router and it's config).

The various web based options will provide exactly what you need, If you're putting together a project that requires such a service then you should harden your code enough to cope if one is down (there's been several options listed in this thread) and/or look to making your own similar service where you can guarantee the uptime or helping to fund one of the existing ones.

User avatar
DougieLawson
Posts: 35536
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Public/External IP

Sat Apr 01, 2017 9:02 am

Code: Select all

#!/bin/bash
dig +short myip.opendns.com \@resolver1.opendns.com 
If that doesn't work then the internets are fundamentally broken and World War III has started.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

martinmmps
Posts: 44
Joined: Fri Apr 29, 2016 5:47 pm

Re: Public/External IP

Sat Apr 01, 2017 4:57 pm

just search on google on your network what is my ip? and it will give you your ip address if you have a dynamic ip and you want dns just use noip (noip.com)
Ubuntu users are apt to get this joke

Return to “Beginners”