Get client public ip address with Server Side Includes

White TV remote with batteries included on a gray couch In a previous episode I showed how to use only a static Nginx configuration to display the client IP address. This is fun, but I thought things could get funnier and compatible with more web servers, while still not using a big dynamic language like PHP or Python.

Although as not as featurefull as PHP or Python, I noticed a lot of things are available in the Server Side Includes (SSI). One of the little gems available are HTTP headers, ready to get displayed in a simple HTML page.

Enable SSI on your web server

First of all, let's enable SSI in the web server. This differs depending on the web server software, but well documented. I'm not going to rewrite them, so here are links to the most-used ones:

What variable to use in your page

Now that the SSI is enabled, getting the client public IP address is just a matter of creating an HTML page with this content:

<!--#echo var="REMOTE_ADDR" -->

More variables are available, here is another example with the user-agent:

<!--#echo var="HTTP_USER_AGENT" -->

I hope you enjoyed this post ! If you did, please share it on your favorite social networks :-)

Photo by me :)