News for hackers. Stuff that matters.
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by nerdponx on Tuesday March 30, 2021 @10:10AM (#26634782)
It's great to have services like this.

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';
      }
    }
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by 0xbkt on Tuesday March 30, 2021 @01:38PM (#26637665)
It is even easier with Caddy's `respond` directive[0], placeholders[1], and automatic HTTPS.

Caddyfile:

  example.com {
      respond "{remote_host}"
  }
[0] https://caddyserver.com/docs/caddyfile/directives/respond

[1] https://caddyserver.com/docs/caddyfile/concepts#placeholders

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by BrandoElFollito on Wednesday March 31, 2021 @03:15AM (#26644356)
One more reason to love that extraordinary web server. It is really wonderful, sad that it is not more used.

I work in IT (was a sysadmin for years, still administer my own servers) and I hated the configuration of the web servers (first Apache, then nginx) - mostly because I was too lazy to read the docs from beginning to end.

This changed with caddy. It is simple, fast, reliable, HTTPS first with LE. Great.

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by banana_giraffe on Tuesday March 30, 2021 @01:14PM (#26637356)
Along the same lines, if you want to make your own AWS Lambda /API Gateway version of this:

    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

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by anonymouse008 on Tuesday March 30, 2021 @01:36PM (#26637648)
That's a brilliant way of adding and removing SSH security group rules for digital nomads
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by banana_giraffe on Tuesday March 30, 2021 @01:42PM (#26637744)
That's exactly what I use it for. I have a small program on my laptop that makes a request of my lambda every now and then (and if it senses a change of the network). It triggers a change in the firewall rules for a SSH server.

Between that and Mosh, I barely even notice when I change networks.

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by rogerdonut on Tuesday March 30, 2021 @01:12PM (#26637327)
This can also be done with HAProxy

    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
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by VWWHFSfQ on Tuesday March 30, 2021 @10:25AM (#26634946)
this service does a lot more than just return your remote_ip, which wont work behind a load-balancer or other proxy unless you configure realip module. and also need to add geoip module to do all the location stuff
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by nerdponx on Tuesday March 30, 2021 @10:37AM (#26635073)
Good points both.

That said, do you know of any software library that exposes the Geoip database (or at least Geoip Lite which you one easily obtain for free) in a nice API? Like how a lot of programming languages have tzinfo/tzdata libraries for querying the Tz database.

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by cryvate1284 on Tuesday March 30, 2021 @11:54AM (#26636140)
Maxmind do APIs for a bunch of language. I've used the python one and it works well (with Lite), but see here their list:

https://dev.maxmind.com/geoip/geoip2/web-services/

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by nerdponx on Tuesday March 30, 2021 @12:14PM (#26636438)
I should clarify that I was looking for an "offline" API/library that I can use against a local copy of the Lite database, but this is great stuff too.
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by luhn on Tuesday March 30, 2021 @01:07PM (#26637238)
Not sure what language you're looking for, but those exist too. Here's a Python one: https://maxminddb.readthedocs.io/en/latest/
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by cryvate1284 on Tuesday March 30, 2021 @02:42PM (#26638565)
If you click through one of the links (e.g. Python) you will see it does allow you to do so!

https://pypi.org/project/geoip2/

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by stevenicr on Tuesday March 30, 2021 @07:30PM (#26641833)
I thought maxmind has some kind of terms change that forced account signup and some other issues 'because of some privacy law' like gdpr - maybe the Cali one?

So it has ruined my second favorite wordpress security plugin - and MaxMind not really usable like it once was (?)

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by banana_giraffe on Tuesday March 30, 2021 @01:18PM (#26637406)
MaxMind offers a small version of their database API for free:

https://dev.maxmind.com/geoip/geoip2/geolite2/

In practice it's good enough for many purposes. It's actually the version of the database that ifconfig.co uses.

Re:Ifconfig.co – Hacker-friendly “What is my IP address” by jesterson on Tuesday March 30, 2021 @11:35PM (#26643238)
nginx with GeoIP2 module does exactly same for me for years by now.
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by enz on Tuesday March 30, 2021 @12:48PM (#26636981)
You can even have the JSON version:

    location /json_ip {
        default_type application/json;
        return 200 "{\"ip\":\"$remote_addr\"}";
    }
Re:Ifconfig.co – Hacker-friendly “What is my IP address” by haik90 on Tuesday March 30, 2021 @01:51PM (#26637879)
been using this for few years. As far as I know, can't return IPv4/IPv6 only from nginx without using separate server block to enforce one of them