Skip to content

Instantly share code, notes, and snippets.

@rz3n
Last active April 13, 2021 17:41
Show Gist options
  • Select an option

  • Save rz3n/c139debddb1837bfa7389a012e51882f to your computer and use it in GitHub Desktop.

Select an option

Save rz3n/c139debddb1837bfa7389a012e51882f to your computer and use it in GitHub Desktop.
Cloudflare Workers
/**
* Return your IPv4 or IPv6 address
*/
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(e) {
let a = '';
for (const element of e.headers) {
a = a.concat(element[0], " => ", element[1], "\n")
}
var host = e.headers.get("host")
var ip = e.headers.get("cf-connecting-ip")
return new Response(ip, {status: 200})
}
@rz3n

rz3n commented Apr 13, 2021

Copy link
Copy Markdown
Author

I use this worker as a simple page to check my public IP address. Very useful when scripting for Mikrotik, bash and what else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment