hackertarget_aslookup
Look up ASN information for a given IP address or ASN using HackerTarget's API. Free tier allows 50 queries per day.
Instructions
Look up ASN information for an IP or ASN via HackerTarget. Free tier: 50 queries/day.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | IP address or ASN to look up |
Implementation Reference
- src/hackertarget/index.ts:52-65 (handler)The main handler function for the hackertarget_aslookup tool. Calls the HackerTarget 'aslookup' API endpoint, parses CSV lines into ASN/IP/owner entries, and returns the result.
export async function hackertargetAslookup(query: string): Promise<AslookupResult> { const text = await htFetch("aslookup", query); const lines = text.split("\n").filter(Boolean); const entries: AslookupResult["entries"] = []; for (const line of lines) { const parts = line.split(",").map((p) => p.trim().replace(/^"|"$/g, "")); if (parts.length >= 3) { entries.push({ asn: parts[0], ip: parts[1], owner: parts[2] }); } } return { query, raw: text, entries }; } - src/hackertarget/index.ts:12-16 (schema)TypeScript interface AslookupResult defining the return type: query string, raw text, and parsed entries array (asn, ip, owner).
interface AslookupResult { query: string; raw: string; entries: { asn: string; ip: string; owner: string }[]; } - src/protocol/tools.ts:426-433 (registration)ToolDef registration for hackertarget_aslookup. Defines name, description, Zod schema (query string), and execute handler that calls hackertargetAslookup.
const hackertargetAslookupTool: ToolDef = { name: "hackertarget_aslookup", description: "Look up ASN information for an IP or ASN via HackerTarget. Free tier: 50 queries/day.", schema: { query: z.string().describe("IP address or ASN to look up"), }, execute: async (args) => json(await hackertargetAslookup(args.query as string)), }; - src/protocol/tools.ts:525-525 (registration)Tool included in the allTools array export alongside other HackerTarget tools.
hackertargetAslookupTool, - src/hackertarget/index.ts:20-28 (helper)Helper function htFetch that performs the actual HTTP request to api.hackertarget.com with rate limiting, error handling, and daily-limit detection.
async function htFetch(endpoint: string, query: string): Promise<string> { await limiter.acquire(); const res = await fetch(`https://api.hackertarget.com/${endpoint}/?q=${encodeURIComponent(query)}`); if (!res.ok) throw new Error(`HackerTarget returned ${res.status}`); const text = await res.text(); if (text.startsWith("error")) throw new Error(`HackerTarget: ${text}`); if (text.includes("API count exceeded")) throw new Error("HackerTarget daily API limit exceeded (50/day free tier)"); return text.trim(); }