If your connection is NAT'ed, is it possible to see your external IP address without making an outbound web request?
Any OS (Windows, Linux, etc.) is fine.
If your connection is NAT'ed, is it possible to see your external IP address without making an outbound web request?
Any OS (Windows, Linux, etc.) is fine.
If your computer is behind NAT, it is possible for you to see the external IP address of your router, but you need administrative access to the router.
The router knows your external IP address, so by accessing its configuration page you can find that IP address. This way does not require any specialized tool except a Web browser.
Other protocols which require a tool for getting the information:
As tested by user @dirkt, all methods only work with IPv4 (except possibly for PCP).
WANIPConn1/GetExternalIPAddress
, and it just successfully returned the correct address.
There are a few ways that work with some NATs but nothing that's guaranteed to work everywhere.
I believe uPnP, NAT-PMP, and PCP (Universal Plug And Play, NAT Port Mapping Protocol, and the Port Control Protocol) all have ways to ask a compliant NAT gateway what the public address is, but not all NATs support these protocols. Support is more common in home gateway routers than in corporate or carrier-grade NAT solutions.
When you find yourself behind a NAT, the only sure way to see what public IP address it is translating your traffic into is to send some outgoing traffic to some public host that will report back, in a way the NAT won't translate, what address your traffic appeared to come from. Using a web based service is one way, but you could also do it by, say, SSHing into a cloud server instance and seeing where sshd
says your SSH session is coming from.
You can use a DNS request, which I believe would not fall under the category of "web request":
nslookup myip.opendns.com resolver1.opendns.com
dig +short @8.8.8.8 o-o.myaddr.l.google.com txt | grep edns
. I found the command here: groups.google.com/d/msg/public-dns-discuss/uyzmMcHQBE0/…
nsslookup
command fails for me. I get Server: resolver1.opendns.com
Address: 2620:119:35::35#53
** server can't find myip.opendns.com: NXDOMAIN
dig
since it's not on Windows. Good point regarding myaddr
for Google though, I wasn't aware of that! I guess the Windows nslookup
equivalent would be nslookup -type=txt o-o.myaddr.l.google.com ns3.google.com
Nov 2, 2018 at 9:12
nslookup
on which IP version to use for transport, but the way OpenDNS does this means you have to. Without that you'd have to predict which IP version nslookup
will use for transport and ask for A or AAAA accordingly. If you are stuck with nslookup
you can use another provider such as Google. However you still get only one protocol version in the response and you cannot choose which.
AAAA
for ns3.google.com
, then feed the resulting IPv6 to nslookup
rather than passing ns3.google.com
.
Nov 3, 2018 at 13:38
I would like to add one point to already existing answers.
It also depends on the network complexity. It is possible that your computer is located within a network that has multiple external IP addresses and the router somewhere up the line sends the traffic out to the Internet based on some criteria: for example, destination IP-address, or time of day (may be one uplink channel is cheaper at night or for other reasons).
So, to be complete, a notion of "external IP address" may require defining a destination point to which your address is being external.
In the example below Router #2
could perform NAT and send traffic to either uplinks and the receiving host could see different external IP-address for the Host
.
Or it could be that a certain destination (for example host1.example.com
) always routes thru the Uplink A
, and the host host2.example.com
always routes via Uplink B
. So, your external IP addresses as seen by those hosts will be different, providing that Uplink A
and Uplink B
are different ISPs.
Uplink A Uplink B
------------- -------------
| |
| |
| 192.168.1.1 192.168.50.50 |
| ----------- |
|---------------|Router #2|---------------|
-----------
| 192.168.100.1
|
| 192.168.100.2
-----------
|Router #1|
-----------
| 192.168.200.1
|
| 192.168.200.2
-----------
| Host |
-----------
So, sending traffic out will allow to get more reliable results.
You can use DNS rather than HTTP. For example you can use:
dig +short TXT o-o.myaddr.l.google.com
This will show the unicast address of the DNS server you are using, and if it supports EDNS it will also show your IP address, though possibly truncated.
To get your full IP address you can bypass your local DNS server and send above request directly to ns{1,2,3,4}.google.com
dig +short TXT o-o.myaddr.l.google.com @ns3.google.com
If you want to see your IP address in a specific protocol version you can use -6
and -4
:
dig -6 +short TXT o-o.myaddr.l.google.com @ns3.google.com
dig -4 +short TXT o-o.myaddr.l.google.com @ns3.google.com
You can also use OpenDNS if you so prefer. OpenDNS doesn't use TXT records for this but rather A and AAAA records, so you have to specify which protocol version you are looking for:
dig -6 +short AAAA myip.opendns.com @resolver2.opendns.com
dig -4 +short A myip.opendns.com @resolver2.opendns.com
Notice that if your traffic goes through protocol translation you may get different results or none at all. Testing from a machine behind NAT64 I was able to see my IPv6 address with the above commands but not the IPv4 address of the NAT64.
This answer is based on these sources 1 2 3 and a bit research of my own.
Web generally refers to HTTP, if that is the meaning of your question, then for instance, you could use STUN ( Wikipedia Article ) which stands for "Session Traversal Utilities for NAT".
Now as it's been highlighted in a comment, you may have multiple external IPs. Also as wireless connections are becoming more common (thing 4G), it is not impossible that the IP address reported by your router would not be a public one. I've even met that scenario on optic fiber connections in some countries, where the ISP would give the local router a private IP, that would get 1:1 translated to a public IP later when leaving their network.
So if your question is "can I find my public IP without sending packets out of my network", you MIGHT in your context, but there's no 100% proof solution.