MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / fetchDnsWithFallback

Function fetchDnsWithFallback

bgp/bgp.ts:156–188  ·  view source on GitHub ↗
(ip: string)

Source from the content-addressed store, hash-verified

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
183function extractTopLevelDomain(domain: string): string {
184 const parts = domain.split(".");
185 if (parts.length >= 2) return parts.slice(-2).join(".");
186 return domain;
187}
188
189function extractDNSData(html: string): {
190 dnsLines: string[];
191 totalRecords: number;

Callers 1

BGPPluginClass · 0.85

Calls 4

networkAddressFunction · 0.85
extractDNSDataFunction · 0.85
isValidIPv4Function · 0.70
getMethod · 0.45

Tested by

no test coverage detected