Elffuss BraidHub

kikocis/osiris public

master · 967 BRawPermalink
1import { NextResponse } from 'next/server';
2
3export async function GET(req: Request) {
4 const { searchParams } = new URL(req.url);
5 const ip = searchParams.get('ip');
6
7 if (!ip) {
8 return NextResponse.json({ error: 'Missing IP parameter' }, { status: 400 });
9 }
10
11 try {
12 const res = await fetch(`https://internetdb.shodan.io/${encodeURIComponent(ip)}`, {
13 signal: AbortSignal.timeout(8000),
14 cache: 'no-store'
15 });
16
17 if (res.status === 404) {
18 return NextResponse.json({
19 ip,
20 status: 'No Shodan InternetDB records found',
21 ports: [],
22 cpes: [],
23 hostnames: [],
24 tags: [],
25 vulns: []
26 });
27 }
28
29 if (!res.ok) {
30 throw new Error(`Shodan HTTP ${res.status}`);
31 }
32
33 const data = await res.json();
34 return NextResponse.json(data);
35 } catch (error: any) {
36 return NextResponse.json({ error: 'Shodan lookup failed', detail: error.message }, { status: 502 });
37 }
38}