Code Monkey home page Code Monkey logo

ipinfo's Introduction

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" : "v0.1.1"
}

or launch:

$ composer require davidepastore/ipinfo

How to use

Set your 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"
));

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

Issues

If you have issues, just open one here.

ipinfo's People

Contributors

davidepastore avatar rvanlaak avatar jamesfairhurst avatar cmwelsh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.