Skip to content

A GitHub Action that reports the runner's public IP address and location

github action to detect ip addresses

I wanted to know where GitHub-hosted runners are, so I wrote a small action that finds the runner’s public IP address and looks up information about it. It calls two free HTTP APIs:

  • jsonip.com returns the caller’s IP address as {"ip": "..."}. Depending on the network this can be an IPv4 or IPv6 address.
  • An IP lookup API that returns the country, city, and network (ASN) for an address. The original action used https://iplist.cc/api/{ip}; the example below uses https://ipinfo.io/{ip}/json.

An ipinfo.io response looks like this (abbreviated):

{
"ip": "8.8.8.8",
"hostname": "dns.google",
"city": "Mountain View",
"region": "California",
"country": "US",
"org": "AS15169 Google LLC",
"timezone": "America/Los_Angeles"
}

Both requests use Node’s built-in https module wrapped in a promise, so the action has no runtime dependencies besides @actions/core. Two details matter for error handling: network errors are emitted on the request object returned by https.get, not on the response, and JSON.parse can throw if the API returns an HTML error page.

import https from 'https'
export interface IPResponse {
ip: string
city?: string
region?: string
country?: string
org?: string
[key: string]: unknown
}
function getJson<T>(url: string): Promise<T> {
return new Promise((resolve, reject) => {
https
.get(url, res => {
if (res.statusCode !== 200) {
res.resume()
reject(new Error(`${url} returned HTTP ${res.statusCode}`))
return
}
res.setEncoding('utf8')
let body = ''
res.on('data', chunk => {
body += chunk
})
res.on('end', () => {
try {
resolve(JSON.parse(body) as T)
} catch (error) {
reject(error)
}
})
})
.on('error', reject)
})
}
export async function getIpAddress(): Promise<string> {
const json = await getJson<{ip: string}>('https://jsonip.com')
return json.ip
}
export async function getIpInfo(ip: string): Promise<IPResponse> {
return getJson<IPResponse>(`https://ipinfo.io/${ip}/json`)
}

On Node 18 and later you could replace getJson with the built-in fetch; the https version works on any Node release.

The entry point gets the IP, looks it up, and sets one step output per field, plus ip_raw with the whole object. core.setOutput serialises non-string values to JSON. The milliseconds input and wait helper are left over from the TypeScript action template the project was generated from.

import * as core from '@actions/core'
import {getIpAddress, getIpInfo} from './ip'
import {wait} from './wait'
async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`) // only shown when ACTIONS_STEP_DEBUG is true
await wait(parseInt(ms, 10))
const ipAddressOfRunner = await getIpAddress()
core.debug(`ipAddressOfRunner: ${ipAddressOfRunner}`)
const ipInfo = await getIpInfo(ipAddressOfRunner)
core.notice(`ipInfo: ${JSON.stringify(ipInfo)}`)
core.setOutput('ip_raw', ipInfo)
for (const [key, value] of Object.entries(ipInfo)) {
core.setOutput(key, value)
}
core.notice(`ip: ${ipInfo.ip}`)
core.notice(`country: ${ipInfo.country}`)
} catch (error) {
core.setFailed(error instanceof Error ? error.message : String(error))
}
}
run()
steps:
- uses: actions/checkout@v7
- uses: FriendlyUser/ip_address_of_runner@v1.0.0
id: ip-step
with:
milliseconds: 1000
- run: |
echo "raw: ${{ steps.ip-step.outputs.ip_raw }}"
echo "ip: ${{ steps.ip-step.outputs.ip }}"
echo "country: ${{ steps.ip-step.outputs.countryname }}"

Outputs are named after the fields in the lookup response, so with the original iplist.cc API the country was in countryname; with ipinfo.io it would be country. A run in 2023 printed a US address for the runner:

ip: 104.45.204.209
country: United States of America

© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)