Skip to content

tarna/ip-worker

Repository files navigation

IP Worker

A simple cloudflare worker that returns the IP address of a request. It also contains a bunch of different information about that IP provided by cloudflare.

Endpoints

Deploy

Deploy to Cloudflare Workers

Usage

JavaScript / TypeScript

const data = await fetch('https://ip.tarna.workers.dev').then(res => res.json());
console.log(data);

Python

import requests

response = requests.get('https://ip.tarna.workers.dev')
data = response.json()
print(data)

Kotlin

import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URI

fun main() {
    val url = URI.create("https://ip.tarna.workers.dev").toURL()
    with(url.openConnection() as HttpURLConnection) {
        requestMethod = "GET"

        inputStream.bufferedReader().use {
            val response = it.readText()
            val json = JSONObject(response)
            println(json.toString(4))
        }
    }
}

Java

import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URI;

public class Main {
    public static void main(String[] args) {
        try {
            URI url = URI.create("https://ip.tarna.workers.dev");
            HttpURLConnection conn = (HttpURLConnection) url.toURL().openConnection();
            conn.setRequestMethod("GET");

            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder content = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }

            in.close();
            conn.disconnect();

            JSONObject json = new JSONObject(content.toString());
            System.out.println(json.toString(4));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Releases

No releases published

Packages

No packages published