ipinfo

A wrapper around the ipinfo.io services

  • 所有者: DavidePastore/ipinfo
  • 平台:
  • 許可證: GNU General Public License v3.0
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

ipinfo

Latest version
Build Status
Coverage Status
Quality Score
Total Downloads

Build Status
PSR2 Conformance

A wrapper around the ipinfo.io services.

Install

You can install the library using composer. Add these lines in your composer.json:

"require" : {
	"davidepastore/ipinfo" : "^0.4.*"
}

or launch:

$ composer require davidepastore/ipinfo

How to use

Settings

Token

You can set your token when you instantiate the object but it's not mandatory.

$ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
	"token" => "your_api_key"
));

cURL options

The cURL options to use while trying to connect when you instantiate the object:

$ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
	"curlOptions" => array(
            CURLOPT_CONNECTTIMEOUT => 1,
            CURLOPT_TIMEOUT => 2,
            CURLOPT_CAINFO => __DIR__ . "/cacert.pem"
    )
));

Read details about the given ip

You can read all the properties from the given ip.

//Get all the properties
$host = $ipInfo->getFullIpDetails("8.8.8.8");

//Get only a single property (this could save bandwidth)
$city = $ipInfo->getSpecificField("8.8.8.8", DavidePastore\Ipinfo\Ipinfo::CITY);

Read details about your ip

You can read all the properties from your ip.

//Get all the properties
$host = $ipInfo->getYourOwnIpDetails();

//Get only a single property (this could save bandwidth)
$city = $ipInfo->getYourOwnIpSpecificField(DavidePastore\Ipinfo\Ipinfo::CITY);

Get info from the host

After obtaining the Host instance you can read all the properties or each of them individually.

//Read all the properties
$city = $host->getCity();
$country = $host->getCountry();
$hostname = $host->getHostname();
$ip = $host->getIp();
$loc = $host->getLoc();
$org = $host->getOrg();
$phone = $host->getPhone();
$postal = $host->getPostal();
$region = $host->getRegion();

//Get the associative array with all the properties
$properties = $host->getProperties();

Read only a field

There are different constants that you could use to read specific field value from an Ipinfo instance using the getSpecificField() and getYourOwnIpSpecificField() methods:

IpInfo::IP; //For the ip address
IpInfo::HOSTNAME; //For the hostname
IpInfo::LOC; //For the loc
IpInfo::ORG; //For the org
IpInfo::CITY; //For the city
IpInfo::REGION; //For the region
IpInfo::COUNTRY; //For the country
IpInfo::PHONE; //For the phone
IpInfo::POSTAL; //For the postal
IpInfo::GEO; //For the geo info. See the paragraph below for more info

Read only the Geo data (which is faster)

By using the getIpGeoDetails() method you will get less fields. This call tends to be faster than getFullIpDetails() so use this call in case you only need the following fields:

IpInfo::IP; //For the ip address
IpInfo::CITY; //For the city
IpInfo::REGION; //For the region
IpInfo::COUNTRY; //For the country
IpInfo::PHONE; //For the phone
IpInfo::POSTAL; //For the postal

These fields will be empty:

IpInfo::HOSTNAME; //For the hostname
IpInfo::LOC; //For the loc
IpInfo::ORG; //For the org

Error Handling

You can handle all the types of IpInfo exceptions by catching the IpInfoExceptionException:

use DavidePastore\Ipinfo\Exception\IpInfoExceptionException;

try {
    $host = $ipInfo->getFullIpDetails("8.8.8.8");
} catch (IpInfoExceptionException $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Invalid Token Exception

It could happen that the token you are using to make the API call is not valid. You can handle it by catching the InvalidTokenException:

use DavidePastore\Ipinfo\Exception\InvalidTokenException;

try {
    $host = $ipInfo->getFullIpDetails("8.8.8.8");
} catch (InvalidTokenException $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Rate Limit Exceed Exception

It could happen that your API call exceeds the rate limit. You can handle it by catching the RateLimitExceedException:

use DavidePastore\Ipinfo\Exception\RateLimitExceedException;

try {
    $host = $ipInfo->getFullIpDetails("8.8.8.8");
} catch (RateLimitExceedException $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Issues

If you have issues, just open one here.

主要指標

概覽
名稱與所有者DavidePastore/ipinfo
主編程語言PHP
編程語言PHP (語言數: 1)
平台
許可證GNU General Public License v3.0
所有者活动
創建於2014-10-09 11:10:15
推送於2022-12-20 19:22:04
最后一次提交2022-12-20 20:17:17
發布數11
最新版本名稱v0.7.0 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數52
關注者數13
派生數18
提交數125
已啟用問題?
問題數25
打開的問題數0
拉請求數33
打開的拉請求數0
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?