getRealIp(); if ($checkIp) { $ip = gethostbyname($checkIp); } $filepath = '/usr/src/myapp/lib/qqwry.dat'; $location = IpLocation::getLocation($ip, $filepath); return json(['ip' => $ip, 'location' => $location]); } public function location(Request $request, $checkIp = null) { $ip = $request->getRealIp(); if ($checkIp) { $ip = gethostbyname($checkIp); } $ipNum = ip2long($ip); $record = Ip2locationDb11Model::query()->where( 'ip_from', '<=', $ipNum )->where( 'ip_to', '>=', $ipNum )->first(); if ($record) { $record = $record->toArray(); } else { $record = []; } return json(['ip' => $ip, 'record' => $record]); } }