From d70b9264e776ae4c023c2814fd9a418352e35238 Mon Sep 17 00:00:00 2001 From: Alexander Bruegmann Date: Sun, 31 Jan 2021 16:38:00 +0100 Subject: [PATCH] add methods to fetch ASN information from Team Cymru --- calls.php | 9 ++++++++- class.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/calls.php b/calls.php index 6e6c01f..ec7ee06 100644 --- a/calls.php +++ b/calls.php @@ -37,7 +37,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $idle->viewMoreDomainModal($_GET['id']);//View more details modal } } elseif ($_GET['type'] == 'dns_search') { - $idle->getIpForDomain($_GET['hostname'], $_GET['dns_type']); + header('Content-Type: text/html; charset=utf-8'); + echo $idle->getIpForDomain($_GET['hostname'], $_GET['dns_type']); + } elseif ($_GET['type'] == 'asn_search') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->getAsnForIp($_GET['ip']); + } elseif ($_GET['type'] == 'asn_name') { + header('Content-Type: text/html; charset=utf-8'); + echo $idle->getAsnName($_GET['asn']); } elseif ($_GET['type'] == 'check_up') { echo $idle->checkIsUp($_GET['host']); } elseif ($_GET['type'] == 'object_cards') { diff --git a/class.php b/class.php index 3277c13..69a6a62 100644 --- a/class.php +++ b/class.php @@ -3086,9 +3086,55 @@ class idlers extends helperFunctions return $data['0']['ipv6']; } break; + case "TXT": + $data = dns_get_record($domain, DNS_TXT); + if (isset($data['0']['txt'])) { + return $data['0']['txt']; + } + break; } return "";//Doesnt exist/null/empty/invalid } + + public function getAsnForIp(string $ip): int + {//Gets ASN for an IP address + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $parts = explode('.',$ip); + $dnslookup = implode('.', array_reverse($parts)) . '.origin.asn.cymru.com.'; + } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { + $addr = inet_pton($ip); + $unpack = unpack('H*hex', $addr); + $hex = $unpack['hex']; + $dnslookup = implode('.', array_reverse(str_split($hex))) . '.origin6.asn.cymru.com.'; + } + + if (isset($dnslookup)) { + $record = $this->getIpForDomain($dnslookup, 'TXT'); + if(!empty($record)) { + // example: 3356 | 4.0.0.0/9 | US | arin | 1992-12-01 + $result = explode(" | ", $record); + $asn = array_shift($result); + return $asn; + } + } + + return 0;//Doesnt exist/null/empty/invalid + } + + public function getAsnName(int $asn): string + {//Gets ASN description for an ASN id + //AS3356.asn.cymru.com + $dnslookup = 'AS' . $asn . '.asn.cymru.com.'; + $record = $this->getIpForDomain($dnslookup, 'TXT'); + if(!empty($record)) { + // example: 3356 | US | arin | 2000-03-10 | LEVEL3, US + $result = explode(" | ", $record); + $name = end($result); + return $name; + } + + return "";//Doesnt exist/null/empty/invalid + } public function checkIsUp(string $host, int $port = 80, int $wait_time = 1): int {//Check if host/ip is "up"