/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $params = ['index' => $this->versionedIndex, 'body' => $this->getIndexMapping()];
     $this->esClient->indices()->create($params);
     $this->info('Updating the IPv4, IPv6 and ASN RIR allocated resources');
     foreach (Rir::all() as $rir) {
         $this->warn('===================================================');
         $this->info('Downloading ' . $rir->name . ' allocation list');
         $rirAllocationData = $this->getContents($rir->allocation_list_url);
         $this->getAllocations($rir, $rirAllocationData);
     }
     $this->insertAllocations('asns', $this->seenAsnAllocation);
     $this->insertAllocations('prefixes', $this->seenIpv4Allocation);
     $this->insertAllocations('prefixes', $this->seenIpv6Allocation);
     $this->hotSwapIndices($this->versionedIndex, $this->indexName);
 }
Esempio n. 2
0
 public static function getPrefixes($as_number)
 {
     $prefixes = (new IpUtils())->getBgpPrefixes($as_number);
     $rirNames = [];
     foreach (Rir::all() as $rir) {
         $rirNames[$rir->id] = $rir->name;
     }
     $output['ipv4_prefixes'] = [];
     foreach ($prefixes['ipv4'] as $prefix) {
         $prefixWhois = $prefix->whois;
         $prefixOutput['prefix'] = $prefix->ip . '/' . $prefix->cidr;
         $prefixOutput['ip'] = $prefix->ip;
         $prefixOutput['cidr'] = $prefix->cidr;
         $prefixOutput['roa_status'] = $prefix->roa_status;
         $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;
         $prefixOutput['parent']['prefix'] = empty($prefixWhois->parent_ip) !== true && isset($prefixWhois->parent_cidr) ? $prefixWhois->parent_ip . '/' . $prefixWhois->parent_cidr : null;
         $prefixOutput['parent']['ip'] = empty($prefixWhois->parent_ip) !== true ? $prefixWhois->parent_ip : null;
         $prefixOutput['parent']['cidr'] = empty($prefixWhois->parent_cidr) !== true ? $prefixWhois->parent_cidr : null;
         $prefixOutput['parent']['rir_name'] = empty($prefixWhois->rir_id) !== true ? $rirNames[$prefixWhois->rir_id] : null;
         $prefixOutput['parent']['allocation_status'] = empty($prefixWhois->status) !== true ? $prefixWhois->status : 'unknown';
         $output['ipv4_prefixes'][] = $prefixOutput;
         $prefixOutput = null;
         $prefixWhois = null;
     }
     $output['ipv6_prefixes'] = [];
     foreach ($prefixes['ipv6'] as $prefix) {
         $prefixWhois = $prefix->whois;
         $prefixOutput['prefix'] = $prefix->ip . '/' . $prefix->cidr;
         $prefixOutput['ip'] = $prefix->ip;
         $prefixOutput['cidr'] = $prefix->cidr;
         $prefixOutput['roa_status'] = $prefix->roa_status;
         $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;
         $prefixOutput['parent']['prefix'] = empty($prefixWhois->parent_ip) !== true && isset($prefixWhois->parent_cidr) ? $prefixWhois->parent_ip . '/' . $prefixWhois->parent_cidr : null;
         $prefixOutput['parent']['ip'] = empty($prefixWhois->parent_ip) !== true ? $prefixWhois->parent_ip : null;
         $prefixOutput['parent']['cidr'] = empty($prefixWhois->parent_cidr) !== true ? $prefixWhois->parent_cidr : null;
         $prefixOutput['parent']['rir_name'] = empty($prefixWhois->rir_id) !== true ? $rirNames[$prefixWhois->rir_id] : null;
         $prefixOutput['parent']['allocation_status'] = empty($prefixWhois->status) !== true ? $prefixWhois->status : 'unknown';
         $output['ipv6_prefixes'][] = $prefixOutput;
         $prefixOutput = null;
         $prefixWhois = null;
     }
     return $output;
 }