scan_network_range
Scan a network range in CIDR notation to identify connected devices, retrieve specific fields like IP, ports, or location, and limit results for efficient cybersecurity research.
Instructions
Scan a network range (CIDR notation) for devices
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cidr | Yes | Network range in CIDR notation (e.g., 192.168.1.0/24) | |
| fields | No | List of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name']) | |
| max_items | No | Maximum number of items to include in results (default: 5) |
Implementation Reference
- src/index.ts:1376-1418 (handler)MCP server tool handler for 'scan_network_range'. Validates input, calls ShodanClient.scanNetworkRange, handles errors, and returns JSON-formatted results.case "scan_network_range": { const cidr = String(request.params.arguments?.cidr); if (!cidr) { throw new McpError( ErrorCode.InvalidParams, "CIDR notation is required" ); } const maxItems = Number(request.params.arguments?.max_items) || 5; const fields = Array.isArray(request.params.arguments?.fields) ? request.params.arguments?.fields.map(String) : undefined; try { const scanResults = await shodanClient.scanNetworkRange(cidr, maxItems, fields); // Check if we got an error response from the scan method if (scanResults.error && scanResults.status === 401) { return { content: [{ type: "text", text: JSON.stringify(scanResults, null, 2) }] }; } return { content: [{ type: "text", text: JSON.stringify(scanResults, null, 2) }] }; } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Error scanning network range: ${(error as Error).message}` ); } }
- src/index.ts:189-213 (helper)Core implementation in ShodanClient that converts CIDR to Shodan 'net:' query, performs API search, samples response, and handles API errors including 401 for paid features.async scanNetworkRange(cidr: string, maxItems: number = 5, selectedFields?: string[]): Promise<any> { try { // Convert CIDR to Shodan search query format const query = `net:${cidr}`; const response = await this.axiosInstance.get("/shodan/host/search", { params: { query } }); return this.sampleResponse(response.data, maxItems, selectedFields); } catch (error: unknown) { if (axios.isAxiosError(error)) { if (error.response?.status === 401) { return { error: "Unauthorized: The Shodan search API requires a paid membership. Your API key does not have access to this endpoint.", message: "The network scanning functionality requires a Shodan membership subscription with API access. Please upgrade your Shodan plan to use this feature.", status: 401 }; } throw new McpError( ErrorCode.InternalError, `Shodan API error: ${error.response?.data?.error || error.message}` ); } throw error; } }
- src/index.ts:944-967 (registration)Tool registration in ListToolsRequestSchema handler, including name, description, and input schema definition.name: "scan_network_range", description: "Scan a network range (CIDR notation) for devices", inputSchema: { type: "object", properties: { cidr: { type: "string", description: "Network range in CIDR notation (e.g., 192.168.1.0/24)" }, max_items: { type: "number", description: "Maximum number of items to include in results (default: 5)" }, fields: { type: "array", items: { type: "string" }, description: "List of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name'])" } }, required: ["cidr"] } },
- src/index.ts:947-966 (schema)JSON Schema for input validation of the scan_network_range tool.type: "object", properties: { cidr: { type: "string", description: "Network range in CIDR notation (e.g., 192.168.1.0/24)" }, max_items: { type: "number", description: "Maximum number of items to include in results (default: 5)" }, fields: { type: "array", items: { type: "string" }, description: "List of fields to include in the results (e.g., ['ip_str', 'ports', 'location.country_name'])" } }, required: ["cidr"] }