ip-lookup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseIP Lookup Skill
IP地址查询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):
bash
undefined用途
- 查询多个公共IP信息提供商并汇总结果,生成IP地址的简洁、最匹配的位置和元数据摘要。
功能说明
- 查询至少四个公共源(如ipinfo.io、ip-api.com、ipstack、geoip-db、db-ip、ipgeolocation.io)或其免费端点。
- 标准化返回的数据(国家、地区、城市、经纬度、机构/ASN)并计算简单匹配分数。
- 返回包含最匹配源的紧凑摘要以及其他源的简短表格。
注意事项
- 公共API可能存在速率限制,或者大流量查询需要API密钥;该Skill会尽可能回退到免费端点。
- 地理定位结果为近似值;ISP/网关位置可能与最终用户位置不同。
Bash示例(使用curl + jq):
bash
undefinedBasic usage: IP passed as first arg
Basic usage: IP passed as first arg
IP=${1:-8.8.8.8}
IP=${1:-8.8.8.8}
Query 4 sources
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}" )
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
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):
```javascript
// 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.8Agent 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."
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示例(推荐使用):
```javascript
// 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.8Agent提示词
"使用ip-lookup skill为{ip}查询至少四个公共IP信息提供商。返回简短的JSON摘要:best_match(国家/城市)、score以及各源的详细信息(国家、地区、城市、经纬度、机构)。遵守速率限制,出错时回退到备用端点。"
"创建新Skill时,请遵循SKILL_TEMPLATE.md格式,并包含Node.js和Bash示例。"