For the benefit of anyone interested: for a "self-hosted" solution, you can do this entirely within Nginx. Here's an example config:
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 default_server;
listen [::]:443 default_server;
# Use Letsencrypt for SSL. This part will depend on your own setup.
ssl_certificate /etc/letsencrypt/live/<my domain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<my domain>/privkey.pem;
server_name <my domain>;
# Deny all access at all paths; useful if you're hosting other stuff behind
# the same Nginx server (e.g. reverse proxy)
location / {
deny all;
}
# At /ip, return 200 with the client IP address in the body
location = /ip {
default_type text/plain;
return 200 '$remote_addr';
}
}Caddyfile:
example.com {
respond "{remote_host}"
}
[0] https://caddyserver.com/docs/caddyfile/directives/respond[1] https://caddyserver.com/docs/caddyfile/concepts#placeholders
def lambda_handler(event, context):
return {
'statusCode': '200',
'headers': None,
'body': event.get('requestContext', {}).get('identity', {}).get('sourceIp', 'unknown')
}
I do this, though my lambda is a bit more complex in practice, since I have some triggers that say "if this thing reports a new IP, do something".Of course, AWS provides this basic service as checkip.amazonaws.com
listen whatismyip
bind :::80 # listen on ipv4/ipv6
bind :::443 ssl crt /etc/haproxy/ssl/fullchain.pem
mode http
http-request return status 200 content-type "text/plain" lf-string "%[src]" if { path /ip }
http-request return status 200 content-type "application/json" lf-string "{\"ip\":\"%[src]\"}" if { path /json_ip }
http-request deny location /json_ip {
default_type application/json;
return 200 "{\"ip\":\"$remote_addr\"}";
}If the software behind the service is available and looks like it'll be easily usable for years because it has few to no dependancies that are likely to deprecated, I might actually commit the effort to memory and use it for all similar demands, similar to how I keep track of specific CLI *nix tools which I can rest assured, even if there are no updates and potential security issues, most are going to be usable at some future date in a pinch.
ifconfig.io https://news.ycombinator.com/item?id=17168415
ifconfig.in https://news.ycombinator.com/item?id=4070133
ifconfig.me https://news.ycombinator.com/item?id=6429921
We are so used to NAT that we don't realize how crazy it is that you essentially have to ask a stranger what's your address. It's really difficult to explain this to someone with no networking knowledge. Nothing else works this way: phone numbers, emails or postal addresses.
Some anecdotes:
-At the moment the service has 10 GiB of traffic/day. In February, there were 295 476 879 requests.
-Because the service returns only the IP address and nothing else, the requests are larger than the replies.
-At some point a russian ISP began querying eth0.me from (apparently) all of their eyeball routers. Thousands of devices from their address space would query this service every second, which resulted in many Terabytes of traffic monthly. I decided to block their address space.
This service was run by somebody else up until a few years ago. It became more and more unreliable and went offline. At some point I noticed that the domain had expired. I decided to buy it and run it myself.
It's powered by largest residential proxy network so they almost certainly never gonna ban your IP.
I decided to solve this task in a fast and reliable fashion, so I made a tool which discovers own IP address using major public STUN servers: https://github.com/Snawoot/myip
Program issues parallel queries to public STUN servers to determine public IP address and returns result as soon as quorum of matching responses reached.
Works fast and reliable, especially compared to services requiring HTTPS:
user@dt1:~> time curl https://api.ipify.org
45.152.165.44
real 0m2,515s
user 0m0,030s
sys 0m0,019s
user@dt1:~> time curl ifconfig.co/
45.152.165.44
real 0m0,131s
user 0m0,011s
sys 0m0,008s
user@dt1:~> time myip
45.152.165.44
real 0m0,084s
user 0m0,012s
sys 0m0,012sYou can even lookup info for other up addresses. E.g. https://ipinfo.io/1.1.1.1
$ nslookup myip.opendns.com resolver1.opendns.com
> Country United Kingdom
> Country (ISO code) GB
> In EU? true
Well, that's inaccurate for a start.
http://checkip.amazonaws.com/
http://whatismyip.akamai.com/
dig +short myip.opendns.com @resolver1.opendns.com$ curl ifconfig.me
129.6.255.60
$ curl ifconfig.me/all
ip_addr: 129.6.255.60
remote_host: unavailable
user_agent: curl/7.68.0
port: 52332
in case you just want to import a string. No headers either. (I'm lazy, so this is what I use to get an external IP for my robots)
I always wondered where this info comes from, looking at the similar pattern I presume from the same provider. Is it a premium service from MaxMind or what?
Referring of course to the new Linux commands "ip a sh". :)
I hope he gets around to deploying it properly some day.
Now, all you get is a bunch of spammy sites that block you with a captcha then fill the page with ads.
Hopefully his thing rises to the top of the results.
In EU? true Region England
Error 1020 - Access denied
What happened? This website is using a security service to protect itself from online attacks.
> In EU?: true
How very 2019.
https//ddg.gg?q=my+ip
http://lumtest.com/myip http://lumtest.com/myip.json http://ip.oxylabs.io http://ip-api.com http://api.ipify.org http://ipinfo.io http://icanhazip.com http://ipaddressm.com https://api.myip.com http://httpbin.org/ip http://bot.whatismyipaddress.com https://ipapi.co/json http://ifconfig.io http://ifconfig.pro http://ipfinfo.fun http://checkip.amazonaws.com http://eth0.me http://ident.me http://ipaddress.sh http://ipfree.info https://iphorse.com/json http://myexternalip.com/json http://wgetip.com http://ip.jsontest.com http://thisip.com http://l2.io/ip https://wtfismyip.com/json http://ipecho.net/plain http://ipgrab.io http://whatismyip.akamai.com http://curlmyip.net http://myip.ipip.net http://checkip.dyndns.com http://ip.anysrc.net https://ip.seeip.org http://ipcalf.com
I guess you can count on the proxy networks, the big companies, and the aged ones. Otherwise take your pick based on what's memorable or short.