Example #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(Dns $dns)
 {
     $domainRecords = $dns->getDomainRecords($this->domain);
     foreach ($domainRecords as $type => $records) {
         foreach ($records as $record) {
             /*
             		$dnsEntry = new DNSRecord;
             $dnsEntry->input = $this->domain;
             $dnsEntry->type = $type;
             $dnsEntry->entry = $record;
             */
             if ($type === 'A' || $type === 'AAAA') {
                 $this->ipUtils->ip2dec($record);
             }
             dump($this->domain, $type, $record, '=======================================');
             //$dnsEntry->save();
         }
     }
     echo 'Done: ' . $this->domain . PHP_EOL;
 }
Example #2
0
 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);
 }