Get the FREE Ultimate OpenClaw Setup Guide →

ip-lookup

Scanned
npx machina-cli add skill besoeasy/open-skills/ip-lookup --openclaw
Files (1)
SKILL.md
3.3 KB

IP Lookup Skill

Purpose

  • Query multiple public IP information providers and aggregate results to produce a concise, best-match location and metadata summary for an IP address.

What it does

  • Queries at least four public sources (e.g. ipinfo.io, ip-api.com, ipstack, geoip-db, db-ip, ipgeolocation.io) or their free endpoints.
  • Normalises returned data (country, region, city, lat/lon, org/ASN) and computes a simple match score.
  • Returns a compact summary with the best-matched source and a short table of the other sources.

Notes

  • Public APIs may have rate limits or require API keys for high volume; the skill falls back to free endpoints when possible.
  • Geolocation is approximate; ISP/gateway locations may differ from end-user locations.

Bash example (uses curl + jq):

# Basic usage: IP passed as first arg
IP=${1:-8.8.8.8}

# Query 4 sources
A=$(curl -s "https://ipinfo.io/${IP}/json")
B=$(curl -s "http://ip-api.com/json/${IP}?fields=status,country,regionName,city,lat,lon,org,query")
C=$(curl -s "https://geolocation-db.com/json/${IP}&position=true")
D=$(curl -s "https://api.db-ip.com/v2/free/${IP}" )

# Output best-match heuristics should be implemented in script
echo "One-line summary:"
jq -n '{ip:env.IP,sourceA:A,sourceB:B,sourceC:C,sourceD:D}' --argjson A "$A" --argjson B "$B" --argjson C "$C" --argjson D "$D"

Node.js example (recommended):

// ip_lookup.js
async function fetchJson(url, timeout = 8000){
  const controller = new AbortController();
  const id = setTimeout(()=>controller.abort(), timeout);
  try { const res = await fetch(url, {signal: controller.signal}); clearTimeout(id); if(!res.ok) throw new Error(res.statusText); return await res.json(); } catch(e){ clearTimeout(id); throw e; }
}

async function ipLookup(ip){
  const sources = {
    ipinfo: `https://ipinfo.io/${ip}/json`,
    ipapi: `http://ip-api.com/json/${ip}?fields=status,country,regionName,city,lat,lon,org,query`,
    geodb: `https://geolocation-db.com/json/${ip}&position=true`,
    dbip: `https://api.db-ip.com/v2/free/${ip}`
  };

  const results = {};
  for(const [k,u] of Object.entries(sources)){
    try{ results[k] = await fetchJson(u); } catch(e){ results[k] = {error: e.message}; }
  }

  // Normalise and pick best match (simple majority on country+city)
  const votes = {};
  for(const r of Object.values(results)){
    if(!r || r.error) continue;
    const country = r.country || r.country_name || r.countryCode || null;
    const city = r.city || r.city_name || null;
    const key = `${country||'?'}/${city||'?'}`;
    votes[key] = (votes[key]||0)+1;
  }
  const best = Object.entries(votes).sort((a,b)=>b[1]-a[1])[0];
  return {best: best?best[0]:null,score: best?best[1]:0,results};
}

// Usage: node ip_lookup.js 8.8.8.8

Agent prompt

"Use the ip-lookup skill to query at least four public IP information providers for {ip}. Return a short JSON summary: best_match (country/city), score, and per-source details (country, region, city, lat, lon, org). Respect rate limits and fall back to alternate endpoints on errors."

"When creating a new skill, follow SKILL_TEMPLATE.md format and include Node.js and Bash examples."

Source

git clone https://github.com/besoeasy/open-skills/blob/main/skills/ip-lookup/SKILL.mdView on GitHub

Overview

IP Lookup queries at least four public IP information providers (e.g., ipinfo.io, ip-api.com, geolocation-db, db-ip, ipstack, ipgeolocation.io) to aggregate results and produce a best-match location summary with metadata. It normalizes country, region, city, lat/lon, and org/ASN, scores each source, and returns a concise best-match result along with a compact table of other sources.

How This Skill Works

The skill queries multiple public IP information endpoints in parallel, normalizes disparate field names into a common schema (country, region, city, lat, lon, org/ASN), computes a simple match score (e.g., via country/city majority), selects the best-scoring source as best_match, and returns best_match, score, and per-source details.

When to Use It

  • Analyze a web app login or access event to determine the IP's likely location.
  • Enrich server logs or analytics with a best-guess geolocation for reporting.
  • Triaging a security incident by cross-checking IP origin and reputation across providers.
  • Validating a user-entered IP against expected regional targets for eligibility or routing.
  • Investigating mismatches across providers to understand potential VPNs or ISP-based location shifts.

Quick Start

  1. Step 1: Node.js example: node ip_lookup.js 8.8.8.8
  2. Step 2: Bash example (curl + jq) as in SKILL.md to query four sources
  3. Step 3: Inspect the JSON output for best_match, score, and per-source details

Best Practices

  • Query four or more public sources in parallel to minimize latency and maximize coverage.
  • Normalize fields consistently (country, region, city, lat, lon, org/ASN) across sources.
  • Respect rate limits and gracefully handle partial failures; fall back to free endpoints when needed.
  • Be aware that geolocation is approximate and ISP or gateway locations may differ from end-user location.
  • Store per-source results alongside the best_match to enable auditing and troubleshooting.

Example Use Cases

  • Example 1: IP 8.8.8.8 yields best_match US/Mountain View with high agreement across ipinfo.io, ip-api.com, geolocation-db, and db-ip.
  • Example 2: IP 203.0.113.5 shows country US but city varies; best_match surfaces US to aid triage.
  • Example 3: IP 45.33.32.0 aligns with US region in most sources, enabling region-targeted content.
  • Example 4: An IP behind a corporate VPN returns US in country but inconsistent city data; best_match highlights country-level consensus.
  • Example 5: An IP with partial data from some providers still yields a usable best_match and available per-source details for debugging.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers