bgp_ip
Retrieve BGP routing information for an IP address, revealing matching prefixes, autonomous system numbers, and regional internet registry allocation.
Instructions
Look up BGP routing information for an IP address. Returns matching prefixes, ASNs, and RIR allocation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes | IP address to look up |
Implementation Reference
- src/bgp/index.ts:82-99 (handler)The main handler function `bgpIp` that looks up BGP routing information for an IP address. It calls the BGPView API at `/ip/{ip}`, maps the response to include prefixes (with ASN, name, description, country code) and RIR allocation info, and caches results for 30 minutes.
export async function bgpIp(ip: string): Promise<BgpIpResult> { const key = `ip:${ip}`; const cached = cache.get(key); if (cached) return cached; const data = await bgpFetch(`/ip/${ip}`); const result: BgpIpResult = { ip, prefixes: (data.prefixes ?? []).map((p: any) => ({ prefix: p.prefix, asn: p.asn?.asn, name: p.name, description: p.description, countryCode: p.country_code, })), rir: data.rir_allocation?.rir_name ?? "", }; cache.set(key, result); return result; } - src/bgp/index.ts:21-25 (schema)The `BgpIpResult` interface defining the shape of the response: ip, prefixes (prefix, asn, name, description, countryCode), and rir.
interface BgpIpResult { ip: string; prefixes: { prefix: string; asn: number; name: string; description: string; countryCode: string }[]; rir: string; } - src/protocol/tools.ts:352-359 (registration)The tool definition/registration for 'bgp_ip' with name, description, Zod schema (ip: string), and execute callback that calls bgpIp().
const bgpIpTool: ToolDef = { name: "bgp_ip", description: "Look up BGP routing information for an IP address. Returns matching prefixes, ASNs, and RIR allocation.", schema: { ip: z.string().describe("IP address to look up"), }, execute: async (args) => json(await bgpIp(args.ip as string)), }; - src/protocol/tools.ts:515-518 (registration)Registration of bgpIpTool in the tools array alongside other BGP tools.
// BGP (3) bgpAsnTool, bgpIpTool, bgpPrefixTool, - src/bgp/index.ts:39-46 (helper)The `bgpFetch` helper function making requests to the BGPView API with rate limiting and error handling.
async function bgpFetch(path: string): Promise<any> { await limiter.acquire(); const res = await fetch(`https://api.bgpview.io${path}`); if (!res.ok) throw new Error(`BGPView returned ${res.status}`); const json = await res.json(); if (json.status !== "ok") throw new Error(`BGPView error: ${json.status_message ?? "unknown"}`); return json.data; }