PHP code example of aknife / ip

1. Go to this page and download the library: Download aknife/ip library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aknife / ip example snippets



// 获取IP信息
use Aknife\Ip\IpInfo;

// IPv4
IpInfo::find('159.75.190.197');
/*
[
    'continent' => [
            'code' => 'AS',
            'name' => '亚洲',
    ],
    'country' => [
            'code' => 'CN',
            'name' => '中国',
    ],
    'region' => '广东省',
    'city' => '广州市',
]
*/
// IPv4 en
IpInfo::find('159.75.190.197','en');
/*
[
    [continent] => [
            [code] => 'AS',
            [name] => 'Asia',
    ],
    [country] => [
            [code] => 'CN',
            [name] => 'China',
    ],
    [region] => 'Guangdong',
    [city] => 'Guangzhou'
]
*/

// IPv6
IpInfo::find('2402:4e00:1013:e500:0:940e:29d7:3443','full');
/*
[

    'continent' => [
            'code' => 'AS',
            'en' => 'Asia',
            'zh-CN' => '亚洲'
    ],
    'country' => [
            'code' => 'CN',
            'en' => 'China',
            'zh-CN' => '中国'
    ],
    'region' => [
            'en' => 'Guangdong',
            'zh-CN' => '广东省'
    ],
    'city' => [
            'en' => 'Guangzhou',
            'zh-CN' => '广州市'
    ]
]
*/