Skip to main content
Glama

dns_lookup

Resolve domain names to IP addresses using Shodan's DNS service. Supports batch resolution of multiple hostnames in a single query to map hostnames to their corresponding IP addresses.

Instructions

Resolve domain names to IP addresses using Shodan's DNS service. Supports batch resolution of multiple hostnames in a single query. Returns IP addresses mapped to their corresponding hostnames.

Input Schema

NameRequiredDescriptionDefault
hostnamesYesList of hostnames to resolve.

Input Schema (JSON Schema)

{ "properties": { "hostnames": { "description": "List of hostnames to resolve.", "items": { "type": "string" }, "type": "array" } }, "required": [ "hostnames" ], "type": "object" }

Implementation Reference

  • Handler function for the 'dns_lookup' tool. Parses input arguments using DnsLookupArgsSchema, performs batch DNS resolution by calling Shodan's /dns/resolve API endpoint, formats the results mapping hostnames to IPs, and returns a structured text response.
    case "dns_lookup": { const parsedDnsArgs = DnsLookupArgsSchema.safeParse(args); if (!parsedDnsArgs.success) { throw new Error("Invalid dns_lookup arguments"); } // Join hostnames with commas for the API request const hostnamesString = parsedDnsArgs.data.hostnames.join(","); const result: DnsResponse = await queryShodan("/dns/resolve", { hostnames: hostnamesString }); // Format the response in a user-friendly way const formattedResult = { "DNS Resolutions": Object.entries(result).map(([hostname, ip]) => ({ "Hostname": hostname, "IP Address": ip })), "Summary": { "Total Lookups": Object.keys(result).length, "Queried Hostnames": parsedDnsArgs.data.hostnames } }; return { content: [ { type: "text", text: JSON.stringify(formattedResult, null, 2) }, ], }; }
  • Zod schema defining the input for dns_lookup: an array of hostnames to resolve.
    const DnsLookupArgsSchema = z.object({ hostnames: z.array(z.string()).describe("List of hostnames to resolve."), });
  • src/index.ts:331-335 (registration)
    Registration of the 'dns_lookup' tool in the ListTools response, specifying name, description, and input schema converted to JSON schema.
    { name: "dns_lookup", description: "Resolve domain names to IP addresses using Shodan's DNS service. Supports batch resolution of multiple hostnames in a single query. Returns IP addresses mapped to their corresponding hostnames.", inputSchema: zodToJsonSchema(DnsLookupArgsSchema), },
  • Helper function used by dns_lookup to query the Shodan API, specifically /dns/resolve endpoint with hostnames parameter.
    async function queryShodan(endpoint: string, params: Record<string, any>) { try { const response = await axios.get(`${API_BASE_URL}${endpoint}`, { params: { ...params, key: SHODAN_API_KEY }, timeout: 10000, }); return response.data; } catch (error: any) { const errorMessage = error.response?.data?.error || error.message; logToFile(`Shodan API error: ${errorMessage}`); throw new Error(`Shodan API error: ${errorMessage}`); }
  • TypeScript interface for the DNS resolution response from Shodan API, mapping hostnames to IP addresses.
    interface DnsResponse { [hostname: string]: string; // Maps hostname to IP address }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BurtTheCoder/mcp-shodan'

If you have feedback or need assistance with the MCP directory API, please join our Discord server