import { Injectable } from '@nestjs/common'; import { HttpService } from '../http.service'; export interface BgpRoute { asn?: string; prefix?: string; holder?: string; announced: boolean; source: string; } @Injectable() export class BgpService { constructor(private readonly http: HttpService) {} async lookup(ip: string): Promise { const response = await this.http.json<{ data?: { asns?: string[]; prefix?: string; holder?: string }; }>( `https://stat.ripe.net/data/network-info/data.json?resource=${encodeURIComponent(ip)}`, ); const data = response.data; if (!data?.prefix && !data?.asns?.length) return undefined; return { asn: data.asns?.[0], prefix: data.prefix, holder: data.holder, announced: Boolean(data.asns?.length), source: 'RIPEstat network-info', }; } }