Skip to content

Latest commit

 

History

History
102 lines (89 loc) · 3.35 KB

README-en.md

File metadata and controls

102 lines (89 loc) · 3.35 KB

Ip

A PHP component that gets location information based on IpV4 and IpV6 addresses

Build Status Latest Stable Version License Latest Unstable Version Total Downloads composer.lock

README: 中文/English

Install

$ composer require tim168/ip

Use

require __DIR__ .'/vendor/autoload.php';

use Tim168\Ip\Ip;

Supported language formats

character describe
en english
de german
es spanish
pt-BR portuguese
fr french
ja japanese
zh-CN chinese
ru russian

Get Ip location information

$res = Ip::getIp('json','116.234.222.36')

Example

{
    "status": "success",  
    "country": "China",
    "countryCode": "CN",
    "region": "SH",
    "regionName": "Shanghai",
    "city": "Shanghai",
    "zip": "",
    "lat": 31.0449,
    "lon": 121.4012,
    "timezone": "Asia/Shanghai",
    "isp": "China Telecom (Group)",
    "org": "Chinanet SH",
    "as": "AS4812 China Telecom (Group)",
    "query": "116.234.222.36"
}

Get Xml Format

$res = Ip::getIp('xml','116.234.222.36')

Example

<?xml version="1.0" encoding="UTF-8"?>
<query>
	<status>success</status>
	<country>China</country>
	<countryCode>CN</countryCode>
	<region>SH</region>
	<regionName>Shanghai</regionName>
	<city>Shanghai</city>
	<zip></zip>
	<lat>31.0449</lat>
	<lon>121.4012</lon>
	<timezone>Asia/Shanghai</timezone>
	<isp>China Telecom (Group)</isp>
	<org>Chinanet SH</org>
	<as>AS4812 China Telecom (Group)</as>
	<query>116.234.222.36</query>
</query>

GET Csv Format

$res = Ip::getIp('csv','116.234.222.36')

Example

success,China,CN,SH,Shanghai,Shanghai,,31.0449,121.4012,Asia/Shanghai,China Telecom (Group),Chinanet SH,AS4812 China
Telecom (Group),116.234.222.36

Get Serialization Format

$res = $ip->get('php','116.234.222.36')

Example

a:14:{s:6:"status";s:7:"success";s:7:"country";s:5:"China";s:11:"countryCode";s:2:"CN";s:6:"region";s:2:"SH";s:10:"regionName";s:8:"Shanghai";s:4:"city";s:8:"Shanghai";s:3:"zip";s:0:"";s:3:"lat";d:31.0449;s:3:"lon";d:121.4012;s:8:"timezone";s:13:"Asia/Shanghai";s:3:"isp";s:21:"China
Telecom (Group)";s:3:"org";s:11:"Chinanet SH";s:2:"as";s:28:"AS4812 China Telecom
(Group)";s:5:"query";s:14:"116.234.222.36";}

IpV4 to IpV6

$res = Ip::IpV4toV6('116.234.222.36')

Example

0000:0000:0000:0000:0000:ffff:74ea:de24

IpV6 to IpV4

$res = Ip::IpV6toV4('0000:0000:0000:0000:0000:ffff:74ea:de24')

Example

116.234.222.36

License

MIT

End

Thank you for giving me a star