public function getLiveDns($hostname)
 {
     $pslManager = new PublicSuffixListManager();
     $domainParser = new Parser($pslManager->getList());
     $hostname = strtolower($hostname);
     $baseDomain = $domainParser->getRegisterableDomain($hostname);
     $ipUtils = $this->ipUtils;
     $records = Cache::remember($hostname, 60 * 24, function () use($ipUtils, $hostname) {
         $dns = new Dns(['8.8.8.8', '8.8.4.4', 2]);
         $records = $dns->getDomainRecords($hostname, $testNameserver = false);
         ksort($records);
         if (isset($records['A']) === true) {
             $records['A'] = array_unique($records['A']);
             foreach ($records['A'] as $key => $address) {
                 $geoip = $ipUtils->geoip($address);
                 if ($geoip->country->isoCode) {
                     $country_code = $geoip->country->isoCode;
                     $country_name = $geoip->country->name;
                     $city_name = $geoip->city->name;
                 } else {
                     $ipDec = $this->ipUtils->ip2dec($address);
                     $prefix = IPv4BgpPrefix::where('ip_dec_start', '<=', $ipDec)->where('ip_dec_end', '>=', $ipDec)->orderBy('cidr', 'asc')->first();
                     if ($prefix && ($prefixWhois = $prefix->whois())) {
                         $country_code = $prefixWhois->counrty_code;
                         $country_name = $prefixWhois->counrty_code ? trans('countries.' . $prefixWhois->counrty_code) : null;
                         $city_name = null;
                     } else {
                         $country_code = null;
                         $country_name = 'Unknown';
                         $city_name = null;
                     }
                 }
                 $output['address'] = $address;
                 $output['country_code'] = $country_code;
                 if ($city_name) {
                     $output['location'] = $city_name . ', ' . $country_name;
                 } else {
                     $output['location'] = $country_name;
                 }
                 $records['A'][$key] = $output;
             }
         }
         if (isset($records['AAAA']) === true) {
             $records['AAAA'] = array_unique($records['AAAA']);
             foreach ($records['AAAA'] as $key => $address) {
                 $geoip = $ipUtils->geoip($address);
                 if ($geoip->country->isoCode) {
                     $country_code = $geoip->country->isoCode;
                     $country_name = $geoip->country->name;
                     $city_name = $geoip->city->name;
                 } else {
                     $ipDec = $this->ipUtils->ip2dec($address);
                     $prefix = IPv6BgpPrefix::where('ip_dec_start', '<=', $ipDec)->where('ip_dec_end', '>=', $ipDec)->orderBy('cidr', 'asc')->first();
                     if ($prefix && ($prefixWhois = $prefix->whois())) {
                         $country_code = $prefixWhois->counrty_code;
                         $country_name = $prefixWhois->counrty_code ? trans('countries.' . $prefixWhois->counrty_code) : null;
                         $city_name = null;
                     } else {
                         $country_code = null;
                         $country_name = 'Unknown';
                         $city_name = null;
                     }
                 }
                 $output['address'] = $address;
                 $output['country_code'] = $country_code;
                 if ($city_name) {
                     $output['location'] = $city_name . ', ' . $country_name;
                 } else {
                     $output['location'] = $country_name;
                 }
                 $records['AAAA'][$key] = $output;
             }
         }
         return $records;
     });
     $data['hostname'] = $hostname;
     $data['base_domain'] = $baseDomain;
     $data['dns_records'] = $records;
     return $this->sendData($data);
 }
Exemple #2
0
 public function getBgpPrefixes($input)
 {
     $type = $this->getInputType($input);
     if ($type === 'asn') {
         $ipv4Prefixes = IPv4BgpPrefix::where('asn', $input)->orderBy('ip_dec_start', 'asc')->get();
         $ipv6Prefixes = IPv6BgpPrefix::where('asn', $input)->orderBy('ip_dec_start', 'asc')->get();
         return ['ipv4' => $ipv4Prefixes, 'ipv6' => $ipv6Prefixes];
     } else {
         if ($type === 4) {
             $class = IPv4BgpPrefix::class;
         } else {
             $class = IPv6BgpPrefix::class;
         }
     }
     $ipDec = $this->ip2dec($input);
     $prefixes = $class::where('ip_dec_start', '<=', $ipDec)->where('ip_dec_end', '>=', $ipDec)->orderBy('cidr', 'asc')->get();
     return $prefixes;
 }