Skip to content

A simple JavaScript website to present the IP-Address of the visitor

License

Notifications You must be signed in to change notification settings

diecknet/simple-ip-site

Repository files navigation

About this project

This is a simple serverside/serverless JavaScript website to plainly present the IP-Address of the visitor. It's made specifically to work on Cloudflare Workers Sites. The website itself doesn't need JavaScript to be enabled on the client. But having clientside JavaScript enabled adds an easy "Copy to Clipboard" function. The site is styled with pure CSS, using W3.CSS.

Benefits 🤩

  • 💖 Not commercial, no ulterior motives 💖
  • ❌ No Ads
  • ❌ No Tracking
  • ❌ No unnecessary Logs
  • ❌ No other unnecessary information
  • ✅ Absolutely free to use
  • ✅ Open Source - feel free to host it yourself and change according to your needs
  • ✅ IPv4 and IPv6 support
  • ✅ Simple, clean and responsive layout
  • ✅ Works without (client-side) JavaScript

Live version / Demo

Demo on SimpleIP.de

Deploy for yourself

You can selfhost this project on Cloudflare Workers, which is free 🥰 for upto 100,000 requests per day.

Deploy to Cloudflare Workers

About the code

The source code consists of 2 main folders:

Getting the visitor's IP Address with Cloudflare Workers

The magic is happening in getClientIPInfo(request). Cloudflare is providing informations like visitor IP-Address and location and we can easily use it.

// get country from cloudflare
let location = (request.cf || {}).country
    // if we know which city, prepend to location
    if((request.cf || {}).city) {
        location = ((request.cf || {}).city)+', '+location
    }
// [...]
/* get client ip address by Cloudflare header 'CF-Connecting-IP' */
      ipaddress: request.headers.get('CF-Connecting-IP')

Getting the visitor's IP Address with a PHP script

Since Cloudflare Workers has no method to force IPv4 or IPv6 usage, I've put a small PHP script on another webhost. The webhost is reachable with dedicated hostnames for IPv4 and IPv6. The script is just outputting the IP-Address of the client. The website fetches the info from the PHP script using client-side JavaScript/AJAX. So if the website visitor has JavaScript disabled, the site will only show the primary IP-Address determined by Cloudflare.

Build status

Status Branch Note
Deploy to Cloudflare Workers main Release/live version
Test Build dev Development version

MIT License

This project is licensed under the terms of the MIT license.

About

A simple JavaScript website to present the IP-Address of the visitor

Topics

Resources

License

Stars

Watchers

Forks