Пример #1
0
 public function ip($ip)
 {
     // Check if the IP is in bogon range
     if ($bogon = $this->ipUtils->isBogonAddress($ip)) {
         $bogonParts = explode('/', $bogon);
         $geoip = null;
         $prefixes = [];
         $allocation = null;
         $ptrRecord = null;
         $rirIp = $bogonParts[0];
         $rirCidr = $bogonParts[1];
         $rirPrefix = $bogon;
     } else {
         $prefixes = $this->ipUtils->getBgpPrefixes($ip);
         $geoip = $this->ipUtils->geoip($ip);
         $allocation = $this->ipUtils->getAllocationEntry($ip);
         $ptrRecord = $this->dns->getPtr($ip);
         $rirIp = isset($allocation->ip) ? $allocation->ip : null;
         $rirCidr = isset($allocation->cidr) ? $allocation->cidr : null;
         $rirPrefix = isset($allocation->ip) && isset($allocation->cidr) ? $allocation->ip . '/' . $allocation->cidr : null;
     }
     $output['ip'] = $ip;
     $output['ptr_record'] = $ptrRecord;
     $output['prefixes'] = [];
     foreach ($prefixes as $prefix) {
         $prefixWhois = $prefix->whois;
         $asn = ASN::where('asn', $prefix->asn)->first();
         $prefixOutput['prefix'] = $prefix->ip . '/' . $prefix->cidr;
         $prefixOutput['ip'] = $prefix->ip;
         $prefixOutput['cidr'] = $prefix->cidr;
         $prefixOutput['asn']['asn'] = $prefix->asn;
         $prefixOutput['asn']['name'] = $asn->name;
         $prefixOutput['asn']['description'] = $asn->description;
         $prefixOutput['asn']['country_code'] = empty($asn->counrty_code) !== true ? $asn->counrty_code : null;
         $prefixOutput['name'] = isset($prefixWhois->name) ? $prefixWhois->name : null;
         $prefixOutput['description'] = isset($prefixWhois->description) ? $prefixWhois->description : null;
         $prefixOutput['country_code'] = isset($prefixWhois->counrty_code) ? $prefixWhois->counrty_code : null;
         $output['prefixes'][] = $prefixOutput;
     }
     // Lets sort out the prefix array from smallest to largest
     usort($output['prefixes'], function ($a, $b) {
         return $b['cidr'] - $a['cidr'];
     });
     $output['rir_allocation']['rir_name'] = isset($allocation->rir_name) && empty($allocation->rir_name) !== true ? $allocation->rir_name : null;
     $output['rir_allocation']['country_code'] = isset($allocation->country_code) ? $allocation->country_code : null;
     $output['rir_allocation']['ip'] = $rirIp;
     $output['rir_allocation']['cidr'] = $rirCidr;
     $output['rir_allocation']['prefix'] = $rirPrefix;
     $output['rir_allocation']['date_allocated'] = isset($allocation->date_allocated) ? $allocation->date_allocated . ' 00:00:00' : null;
     $output['rir_allocation']['allocation_status'] = isset($allocation->status) ? $allocation->status : null;
     $output['maxmind']['country_code'] = $geoip ? $geoip->country->isoCode : null;
     $output['maxmind']['city'] = $geoip ? $geoip->city->name : null;
     return $this->sendData($output);
 }
Пример #2
0
 private function updateASN()
 {
     $this->cli->br()->comment('===================================================');
     $this->cli->br()->comment('Adding newly allocated ASNs to queue')->br();
     $sourceAsns = $this->getAllAsns();
     $asns = [];
     foreach ($sourceAsns as $sourceAsn) {
         foreach ($sourceAsn as $asnObj) {
             if (isset($asns[$asnObj->asn]) === false) {
                 $asns[$asnObj->asn] = isset($asnObj->rir_id) ? $asnObj->rir_id : null;
             }
         }
     }
     $seenAsns = DB::table('asns')->pluck('asn');
     $seenAsns = array_flip($seenAsns);
     foreach ($asns as $as_number => $rir_id) {
         // Lets check if the ASN has already been looked at in the past
         if (isset($seenAsns[$as_number]) !== true) {
             // Dispatch a new job into queue
             $this->dispatch(new EnterASNs($as_number, $rir_id, $this->getPeeringDbInfo($as_number)));
         }
     }
     // Ok, now that we are done with new allocations, lets update the old records
     $oldAsns = ASN::where('updated_at', '<', Carbon::now()->subMonth())->orderBy('updated_at', 'ASC')->limit(2000)->get();
     $oldAsns->shuffle();
     foreach ($oldAsns as $oldAsn) {
         $this->dispatch(new UpdateASNs($oldAsn, $this->getPeeringDbInfo($oldAsn->asn)));
     }
 }