(ip: string)
| 154 | const prefixesToTry: string[] = []; |
| 155 | const p24 = networkAddress(ip, 24); |
| 156 | if (p24) prefixesToTry.push(p24); |
| 157 | const p23 = networkAddress(ip, 23); |
| 158 | if (p23 && p23 !== p24) prefixesToTry.push(p23); |
| 159 | |
| 160 | for (const prefix of prefixesToTry) { |
| 161 | const url = `https://bgp.tools/prefix/${prefix}#dns`; |
| 162 | |
| 163 | try { |
| 164 | const response = await axios.get(url, { |
| 165 | headers: BGP_COMMON_HEADERS, |
| 166 | timeout: 15000, |
| 167 | }); |
| 168 | |
| 169 | const dnsResult = extractDNSData(response.data); |
| 170 | |
| 171 | if (dnsResult.dnsLines.length > 0) { |
| 172 | return { dnsLines: dnsResult.dnsLines, usedPrefix: prefix }; |
| 173 | } |
| 174 | } catch (err: any) { |
| 175 | if (err.response?.status === 404) continue; |
| 176 | continue; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | throw new Error("未找到DNS记录"); |
| 181 | } |
| 182 | |
| 183 | function extractTopLevelDomain(domain: string): string { |
| 184 | const parts = domain.split("."); |
| 185 | if (parts.length >= 2) return parts.slice(-2).join("."); |
| 186 | return domain; |
| 187 | } |
| 188 | |
| 189 | function extractDNSData(html: string): { |
| 190 | dnsLines: string[]; |
| 191 | totalRecords: number; |
no test coverage detected