@burtthecoder/mcp-shodan
Version:
A Model Context Protocol server for Shodan API queries.
35 lines (34 loc) • 1.35 kB
JavaScript
import { z } from "zod";
import { queryShodan } from "../helpers.js";
export function registerDnsLookup(server) {
server.addTool({
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.",
parameters: z.object({
hostnames: z
.array(z.string())
.describe("List of hostnames to resolve."),
}),
annotations: {
readOnlyHint: true,
openWorldHint: true,
},
execute: async (args) => {
const hostnamesString = args.hostnames.join(",");
const result = await queryShodan("/dns/resolve", {
hostnames: hostnamesString,
});
const formattedResult = {
"DNS Resolutions": Object.entries(result).map(([hostname, ip]) => ({
Hostname: hostname,
"IP Address": ip,
})),
Summary: {
"Total Lookups": Object.keys(result).length,
"Queried Hostnames": args.hostnames,
},
};
return JSON.stringify(formattedResult, null, 2);
},
});
}