<?php

namespace app\controller;

use itbdw\Ip\IpLocation;
use support\Request;

class Index
{
    public function index(Request $request, $checkIp = null)
    {
        $ip = $request->getRealIp();

        if ($checkIp) {
            $ip = gethostbyname($checkIp);
        }

        $filepath = '/usr/src/myapp/lib/qqwry.dat';

        $location = IpLocation::getLocation($ip, $filepath);

        return json(['ip' => $ip, 'location' => $location]);
    }
}
