(html: string)
| 194 | const dnsLines: string[] = []; |
| 195 | const ipDomainMap = new Map<string, string[]>(); |
| 196 | const domainRecords: Array<{ ip: string; domain: string; topLevelDomain: string }> = []; |
| 197 | |
| 198 | try { |
| 199 | const $ = cheerio.load(html); |
| 200 | const allText = $.text(); |
| 201 | |
| 202 | const ipDomainPattern = |
| 203 | /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g; |
| 204 | |
| 205 | let match: RegExpExecArray | null; |
| 206 | while ((match = ipDomainPattern.exec(allText)) !== null) { |
| 207 | const ip = match[1]; |
| 208 | const domain = match[2]; |
| 209 | const top = extractTopLevelDomain(domain); |
| 210 | |
| 211 | domainRecords.push({ ip, domain, topLevelDomain: top }); |
| 212 | if (!ipDomainMap.has(ip)) ipDomainMap.set(ip, []); |
| 213 | ipDomainMap.get(ip)!.push(domain); |
| 214 | } |
| 215 | |
| 216 | const domainCount = new Map<string, number>(); |
| 217 | domainRecords.forEach((r) => { |
| 218 | domainCount.set(r.topLevelDomain, (domainCount.get(r.topLevelDomain) || 0) + 1); |
| 219 | }); |
| 220 | |
| 221 | const filtered = new Set<string>(); |
| 222 | domainCount.forEach((count, dom) => { |
| 223 | if (count > 2) filtered.add(dom); |
| 224 | }); |
| 225 | |
| 226 | ipDomainMap.forEach((domains, ip) => { |
| 227 | domains.forEach((domain) => { |
| 228 | const top = extractTopLevelDomain(domain); |
| 229 | if (!filtered.has(top)) dnsLines.push(`${ip}\t${domain}`); |
| 230 | }); |
| 231 | }); |
| 232 | |
| 233 | return { |
| 234 | dnsLines, |
| 235 | totalRecords: domainRecords.length, |
| 236 | filteredRecords: domainRecords.length - dnsLines.length, |
| 237 | }; |
| 238 | } catch { |
| 239 | return { dnsLines: [], totalRecords: 0, filteredRecords: 0 }; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | async function resolveTargetIP( |
| 244 | args: string[], |
| 245 | msg: Api.Message, |
| 246 | trigger?: Api.Message, |
| 247 | ): Promise<string | null> { |
| 248 | const rawInput = args.join(" ").trim(); |
| 249 | |
| 250 | if (rawInput) { |
| 251 | const ipFromArgs = extractIPFromText(rawInput); |
no test coverage detected