mirror of
https://github.com/cp6/my-idlers.git
synced 2025-04-19 09:38:36 +00:00
add methods to fetch ASN information from Team Cymru
This commit is contained in:
parent
d6c23a97e3
commit
d70b9264e7
2 changed files with 54 additions and 1 deletions
|
@ -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') {
|
||||
|
|
46
class.php
46
class.php
|
@ -3086,10 +3086,56 @@ 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"
|
||||
if ($fp = @fsockopen($host, $port, $errCode, $errStr, $wait_time)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue