/** * Run the database seeds. * * @return void */ public function run() { Rir::create(['name' => 'AfriNIC', 'full_name' => 'African Network Information Center', 'website' => 'afrinic.net', 'whois_server' => 'whois.afrinic.net', 'allocation_list_url' => 'ftp://ftp.afrinic.net/stats/afrinic/delegated-afrinic-extended-latest']); Rir::create(['name' => 'ARIN', 'full_name' => 'American Registry for Internet Numbers', 'website' => 'arin.net', 'whois_server' => 'whois.arin.net', 'allocation_list_url' => 'ftp://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest']); Rir::create(['name' => 'APNIC', 'full_name' => 'Asia-Pacific Network Information Centre', 'website' => 'apnic.net', 'whois_server' => 'whois.apnic.net', 'allocation_list_url' => 'ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-extended-latest']); Rir::create(['name' => 'Lacnic', 'full_name' => 'Latin America and Caribbean Network Information Centre', 'website' => 'lacnic.net', 'whois_server' => 'whois.lacnic.net', 'allocation_list_url' => 'ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-extended-latest']); Rir::create(['name' => 'RIPE', 'full_name' => 'Reseaux IP Européens Network Coordination Centre', 'website' => 'ripe.net', 'whois_server' => 'whois.ripe.net', 'allocation_list_url' => 'ftp://ftp.ripe.net/ripe/stats/delegated-ripencc-extended-latest']); }
/** * 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); }
public function __construct($input, $cidr = null, $rir = null, $useRaw = false) { $this->esClient = new ClientBuilder(); $this->ipUtils = new IpUtils(); $this->whoisUrl = config('app.whois_query_url'); // Check if we supply direct raw whois details if ($useRaw === true && is_null($rir) !== true) { $this->rir = $rir; $this->rawData = $input; $this->rawLines = explode("\n", $input); return; } $this->input = $this->ipUtils->normalizeInput(trim($input), $showAS = true); $allocation = $this->ipUtils->getAllocationEntry($this->input, $cidr); if (is_null($allocation) === true || empty($allocation) === true) { $assignment = $this->ipUtils->getIanaAssignmentEntry($this->input); if (is_null($assignment) === true || empty($assignment) === true) { $this->rawData = null; $this->rawLines = []; return; } else { $this->rir = Rir::where('whois_server', $assignment->whois_server)->first(); } } else { $this->rir = Rir::find($allocation->rir_id); } if (empty($this->rir) || is_null($this->rir) === true) { $this->rawData = null; $this->rawLines = []; return; } $this->allocationData = $allocation; // Lets fetch the raw whois data if (is_null($cidr) !== true) { $this->input .= '/' . $cidr; } $this->rawData = removeAccents($this->getRawWhois()); $this->rawLines = explode("\n", $this->rawData); }
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; }