public function whois() { if (isset($this->attributes['whois']) !== true) { $this->attributes['whois'] = IPv6PrefixWhois::where('ip', $this->ip)->where('cidr', $this->cidr)->first(); } return $this->attributes['whois']; }
public function search(Request $request) { $queryTerm = $request->get('query_term'); $queryTerm = trim(str_replace(['/', '?', '!', ':', ',', '\'', '-', '_', '.', '+'], "", strtolower($queryTerm))); $elasticQuery['filtered']['query'] = ['bool' => ['should' => [['wildcard' => ['name' => ['value' => '*' . $queryTerm . '*', 'boost' => 2]]], ['wildcard' => ['description' => ['value' => '*' . $queryTerm . '*']]], ['wildcard' => ['name_full' => ['value' => '*' . $queryTerm . '*']]], ['multi_match' => ['query' => $queryTerm, 'fields' => ['asn^5']]]], 'minimum_should_match' => 1]]; $asnSort = [['asn' => ['order' => 'asc']]]; $ipSort = [['ip' => ['order' => 'asc']]]; $asns = ASN::searchByQuery($elasticQuery, $aggregations = null, $sourceFields = null, $limit = 100, $offset = null, $asnSort); $ipv4Prefixes = IPv4PrefixWhois::searchByQuery($elasticQuery, $aggregations = null, $sourceFields = null, $limit = 200, $offset = null, $ipSort); $ipv6Prefixes = IPv6PrefixWhois::searchByQuery($elasticQuery, $aggregations = null, $sourceFields = null, $limit = 200, $offset = null, $ipSort); $ixs = IX::searchByQuery($elasticQuery, $aggregations = null, $sourceFields = null, $limit = 200, $offset = null, $ipSort); $data['asns'] = []; foreach ($asns as $asn) { $asnData['asn'] = $asn->asn; $asnData['name'] = $asn->name; $asnData['description'] = $asn->description; $asnData['country_code'] = empty($asn->counrty_code) !== true ? $asn->counrty_code : null; $asnData['email_contacts'] = $asn->email_contacts; $asnData['abuse_contacts'] = $asn->abuse_contacts; $asnData['rir_name'] = $asn->rir->name; $data['asns'][] = $asnData; } $data['ipv4_prefixes'] = []; foreach ($ipv4Prefixes as $prefix) { $prefixData['prefix'] = $prefix->ip . '/' . $prefix->cidr; $prefixData['ip'] = $prefix->ip; $prefixData['cidr'] = $prefix->cidr; $prefixData['name'] = $prefix->name; $prefixData['country_code'] = empty($prefix->counrty_code) !== true ? $prefix->counrty_code : null; $prefixData['description'] = $prefix->description; $prefixData['email_contacts'] = $prefix->email_contacts; $prefixData['abuse_contacts'] = $prefix->abuse_contacts; $prefixData['rir_name'] = $prefix->rir->name; $prefixData['parent_prefix'] = $prefix->parent_ip . '/' . $prefix->parent_cidr; $prefixData['parent_ip'] = $prefix->parent_ip; $prefixData['parent_cidr'] = $prefix->parent_cidr; $data['ipv4_prefixes'][] = $prefixData; } $data['ipv6_prefixes'] = []; foreach ($ipv6Prefixes as $prefix) { $prefixData['prefix'] = $prefix->ip . '/' . $prefix->cidr; $prefixData['ip'] = $prefix->ip; $prefixData['cidr'] = $prefix->cidr; $prefixData['name'] = $prefix->name; $prefixData['country_code'] = empty($prefix->counrty_code) !== true ? $prefix->counrty_code : null; $prefixData['description'] = $prefix->description; $prefixData['email_contacts'] = $prefix->email_contacts; $prefixData['abuse_contacts'] = $prefix->abuse_contacts; $prefixData['rir_name'] = $prefix->rir->name; $prefixData['parent_prefix'] = $prefix->parent_ip . '/' . $prefix->parent_cidr; $prefixData['parent_ip'] = $prefix->parent_ip; $prefixData['parent_cidr'] = $prefix->parent_cidr; $data['ipv6_prefixes'][] = $prefixData; } $data['internet_exchanges'] = []; foreach ($ixs as $ix) { $ixData['ix_id'] = $ix->id; $ixData['name'] = $ix->name; $ixData['name_full'] = $ix->name_full; $ixData['country_code'] = $ix->counrty_code; $ixData['city'] = $ix->city; $data['internet_exchanges'][] = $ixData; } return $this->sendData($data); }