Skip to content

Instantly share code, notes, and snippets.

@meoyawn
Created April 17, 2026 20:30
Show Gist options
  • Select an option

  • Save meoyawn/d16fdfa7e424ab4d8b05462c176fca92 to your computer and use it in GitHub Desktop.

Select an option

Save meoyawn/d16fdfa7e424ab4d8b05462c176fca92 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bun
const timeoutMs = 5_000;
const sources = ["https://ipv4.icanhazip.com", "https://2ip.ru"] as const;
const results = await Promise.all(
sources.map((url) =>
fetch(url, {
headers: { "User-Agent": "curl/8.0.0" },
signal: AbortSignal.timeout(timeoutMs),
}).then(async (res) => {
if (!res.ok) {
throw new Error(
`${new URL(url).host} responded with HTTP ${res.status}`,
);
}
return [url, await res.text()] as const;
}),
),
);
for (const [url, body] of results) {
console.log(`${new URL(url).host.padEnd(20)} ${body.trim()}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment