PHPackages                             skpassegna/ipregistry-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. skpassegna/ipregistry-php-sdk

ActiveLibrary[API Development](/categories/api)

skpassegna/ipregistry-php-sdk
=============================

IpRegistry PHP SDK (PSR-4 autoloading compatible/Unofficial)

1.0.0(1y ago)026GPL-3.0-or-laterPHPPHP ^8.0

Since Oct 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/skpassegna/ipregistry-php-sdk)[ Packagist](https://packagist.org/packages/skpassegna/ipregistry-php-sdk)[ Docs](https://github.com/skpassegna/ipregistry-php-sdk)[ RSS](/packages/skpassegna-ipregistry-php-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/6b45a39d4682008c24f773d1ded9b28e80f595d3f49289487ac19f7d968baddc/68747470733a2f2f706f7365722e707567782e6f72672f736b7061737365676e612f697072656769737472792d7068702d73646b2f762f737461626c65)](https://packagist.org/packages/skpassegna/ipregistry-php-sdk)[![Total Downloads](https://camo.githubusercontent.com/213791453f7ef0f0104c70548bb2540fa93d7e3681408f58f0d49d05052d818a/68747470733a2f2f706f7365722e707567782e6f72672f736b7061737365676e612f697072656769737472792d7068702d73646b2f646f776e6c6f616473)](https://packagist.org/packages/skpassegna/ipregistry-php-sdk)[![License](https://camo.githubusercontent.com/0bb08538ebe3932b1fb1080c89fa1377a99fc1dd87ac7f43fcaca5b089cfc25f/68747470733a2f2f706f7365722e707567782e6f72672f736b7061737365676e612f697072656769737472792d7068702d73646b2f6c6963656e7365)](https://packagist.org/packages/skpassegna/ipregistry-php-sdk)

1. Introduction
===============

[](#1-introduction)

The Ipregistry PHP SDK is an unofficial library that simplifies interaction with the Ipregistry API, enabling developers to easily access geolocation and threat data for IP addresses and Autonomous Systems (ASNs) within their PHP applications.

**Key Features:**

- **Complete API Coverage:** Supports all Ipregistry API endpoints, including single and batch lookups for IPs and ASNs, origin lookups, and User-Agent parsing.
- **JSON and XML Support:** Handles responses in both JSON (default) and XML formats.
- **Robust Error Handling:** Throws specific exceptions for Ipregistry API error codes and network errors, aiding in debugging.
- **Convenience Methods:** Provides easy-to-use methods for accessing data fields from responses.
- **Composer Integration:** Installable and managed through Composer for easy dependency management.
- **PSR-4 Autoloading:** Adheres to PSR-4 autoloading standards for seamless integration into PHP projects.

2. Installation
===============

[](#2-installation)

The SDK is distributed as a Composer package. To install it, run the following command in your project's root directory:

```
composer require skpassegna/ipregistry-php-sdk
```

3. Getting Started
==================

[](#3-getting-started)

3.1. Obtain an API Key:
-----------------------

[](#31-obtain-an-api-key)

Sign up for a free Ipregistry account at  to obtain your API key.

3.2. Configure the SDK:
-----------------------

[](#32-configure-the-sdk)

```
use Ipregistry\Sdk\IpRegistryClient;
use Ipregistry\Sdk\Config;

// Replace 'YOUR_API_KEY' with your actual Ipregistry API key.
$config = new Config('YOUR_API_KEY');

// (Optional) Customize base URL, timeout, hostname lookup, and output format:
// $config = new Config(
//     'YOUR_API_KEY',
//     Ipregistry\Sdk\Constants::EU_BASE_URL, // Use EU base URL
//     10,                                   // Set timeout to 10 seconds
//     true,                                  // Enable hostname lookup
//     'xml'                                 // Set output format to XML
// );

$client = new IpRegistryClient($config);
```

4. Usage: Endpoints and Methods
===============================

[](#4-usage-endpoints-and-methods)

The SDK provides separate classes for each API endpoint group:

- `Ipregistry\Sdk\Endpoint\IpLookup`: Handles IP address lookups.
- `Ipregistry\Sdk\Endpoint\ASNLookup`: Handles ASN lookups.
- `Ipregistry\Sdk\Endpoint\UserAgentParsing`: Handles User-Agent parsing.

4.1. IP Address Lookup (`IpLookup`)
-----------------------------------

[](#41-ip-address-lookup-iplookup)

- **Single IP Lookup:**

    ```
    $ipLookup = new IpLookup($client);
    $response = $ipLookup->lookup('8.8.8.8');

    echo "IP Address: " . $response->getIp() . PHP_EOL;
    echo "Country: " . $response->getCountryName() . PHP_EOL;
    echo "City: " . $response->getCity() . PHP_EOL;
    // ... Access other IP-related data fields
    ```
- **Batch IP Lookup:**

    ```
    $ips = ['8.8.8.8', '1.1.1.1', '2001:4860:4860::8888'];
    $batchResponse = $ipLookup->batchLookup($ips);

    foreach ($batchResponse->getData()['results'] as $result) {
        echo "IP: " . $result['ip'] . ", Country: " . $result['location']['country']['name'] . PHP_EOL;
    }
    ```
- **Origin IP Lookup:**

    ```
    $originResponse = $ipLookup->originLookup();

    echo "Originating IP: " . $originResponse->getIp() . PHP_EOL;
    ```

4.2. ASN Lookup (`ASNLookup`)
-----------------------------

[](#42-asn-lookup-asnlookup)

- **Single ASN Lookup:**

    ```
    $asnLookup = new ASNLookup($client);
    $response = $asnLookup->lookup(15169);

    echo "ASN Name: " . $response->getAsnName() . PHP_EOL;
    // ... Access other ASN-related data fields
    ```
- **Batch ASN Lookup:**

    ```
    $asns = [15169, 20940];
    $batchResponse = $asnLookup->batchLookup($asns);

    foreach ($batchResponse->getData()['results'] as $result) {
        echo "ASN: " . $result['asn'] . ", Name: " . $result['name'] . PHP_EOL;
    }
    ```
- **Origin ASN Lookup:**

    ```
    $originResponse = $asnLookup->originLookup();

    echo "Originating ASN: " . $originResponse->getAsn() . PHP_EOL;
    ```

4.3. User-Agent Parsing (`UserAgentParsing`)
--------------------------------------------

[](#43-user-agent-parsing-useragentparsing)

- **Single User-Agent Parsing:**

    ```
    $userAgentParsing = new UserAgentParsing($client);
    $response = $userAgentParsing->parse('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');

    echo "Browser: " . $response->getUserAgentName() . PHP_EOL;
    echo "Operating System: " . $response->getOsName() . PHP_EOL;
    // ... Access other User-Agent related data fields
    ```
- **Batch User-Agent Parsing:**

    ```
    $userAgents = [
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
        'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
    ];
    $batchResponse = $userAgentParsing->batchParse($userAgents);

    foreach ($batchResponse->getData()['results'] as $result) {
        echo "User-Agent: " . $result['user_agent']['header'] . ", Browser: " . $result['user_agent']['name'] . PHP_EOL;
    }
    ```
- **Origin User-Agent Parsing:**

    ```
    $originResponse = $userAgentParsing->originParse();

    echo "Originating User-Agent: " . $originResponse->getUserAgentHeader() . PHP_EOL;
    ```

5. Accessing Response Data
==========================

[](#5-accessing-response-data)

The `Ipregistry\Sdk\Response` class handles API responses and provides methods for accessing data:

- **`getData()`:** Returns the parsed response data as an array (for JSON) or an object (for XML).
- **`getRawResponse()`:** Returns the raw Guzzle `ResponseInterface` object.
- **Convenience Methods (Getters):** The `Response` class provides a comprehensive set of convenience methods (getters) for accessing specific data fields from the API responses. These methods follow a consistent naming convention:

    - **`get[FieldName]()`:** Used for most fields, where `[FieldName]` is the CamelCase representation of the field name in the API response.
        - *Examples:* `getIp()`, `getCountryCode()`, `getTimeZoneId()`, `getUserAgentName()`.
    - **`is[FieldName]()`:** Used for boolean fields, where `[FieldName]` is the CamelCase representation of the field name.
        - *Examples:* `isInEu()`, `isVpn()`, `isTor()`.
    - **`raw()`:** Returns the raw Guzzle `ResponseInterface` object.

**Example:**

```
$response = $ipLookup->lookup('8.8.8.8');

// Access data using getData()
$data = $response->getData();
echo "Country Code: " . $data['location']['country']['code'] . PHP_EOL; // Assuming JSON format

// Access data using convenience methods
echo "Country Name: " . $response->getCountryName() . PHP_EOL;
echo "Is in EU: " . ($response->isInEu() ? 'Yes' : 'No') . PHP_EOL;
```

Refer to the `Ipregistry\Sdk\Response` class documentation for a complete list of available convenience methods.

6. Error Handling
=================

[](#6-error-handling)

The SDK uses a structured exception system to handle errors:

- **`Ipregistry\Sdk\Exception\IpregistryException`:** The base exception class for all SDK-specific errors.
- **Specific Exception Classes:** Subclasses of `IpregistryException` are thrown for specific Ipregistry API error codes. These include:
    - `InvalidApiKeyException`
    - `InsufficientCreditsException`
    - `BadRequestException`
    - `ForbiddenIpException`
    - `ForbiddenOriginException`
    - `ForbiddenIpOriginException`
    - `InvalidAsnException`
    - `InvalidIpAddressException`
    - `MissingApiKeyException`
    - `ReservedAsnException`
    - `ReservedIpAddressException`
    - `TooManyAsnsException`
    - `TooManyIpsException`
    - `TooManyRequestsException`
    - `TooManyUserAgentsException`
    - `UnknownAsnException`
- **Guzzle Exceptions:** Network-related exceptions from Guzzle (e.g., `ConnectException`, `RequestException`) are thrown for connectivity issues or request failures.

**Exception Properties:**

- `$errorCode`: The Ipregistry API error code (if available).
- `$resolution`: A suggestion from the Ipregistry API on how to resolve the error (if available).

**Example Error Handling:**

```
try {
    $response = $ipLookup->lookup('invalid-ip');
} catch (Ipregistry\Sdk\Exception\InvalidIpAddressException $e) {
    echo "Error: " . $e->getMessage() . PHP_EOL;
    echo "Error Code: " . $e->getErrorCode() . PHP_EOL;
    echo "Resolution: " . $e->getResolution() . PHP_EOL;
} catch (Exception $e) {
    // Handle other exceptions.
}
```

7. Configuration Options
========================

[](#7-configuration-options)

The SDK's behavior can be customized using the `Ipregistry\Sdk\Config` class:

- **`apiKey` (required):** Your Ipregistry API key.
- **`baseUrl` (optional):** The Ipregistry API base URL. Defaults to `https://api.ipregistry.co`. You can use constants from `Ipregistry\Sdk\Constants` to set regional base URLs (e.g., `Constants::EU_BASE_URL`).
- **`timeout` (optional):** Request timeout in seconds. Defaults to 5.
- **`hostname` (optional):** Enable hostname lookup for IP address lookups. Defaults to `false`.
- **`format` (optional):** The desired output format. Accepts `'json'` (default) or `'xml'`.

**Example Configuration:**

```
$config = new Config(
    'YOUR_API_KEY',
    Ipregistry\Sdk\Constants::EU_BASE_URL, // Use EU base URL
    10,                                   // Set timeout to 10 seconds
    true,                                  // Enable hostname lookup
    'xml'                                 // Set output format to XML
);
```

8. Testing (not completed)
==========================

[](#8-testing-not-completed)

The SDK includes a comprehensive suite of unit tests using PHPUnit to ensure its reliability and correctness. The tests cover all endpoints, methods, and error scenarios.

**Running Tests:**

From the project's root directory, run:

```
./vendor/bin/phpunit
```

9. Contributing
===============

[](#9-contributing)

Contributions to the Ipregistry PHP SDK are welcome! Please open an issue or submit a pull request on GitHub.

10. License
===========

[](#10-license)

This SDK is licensed under the GPL-3.0-or-later License.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

585d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/15eabcf70f69fe482d6f4b77313220540a567fe81039134b554cdd017419bfe2?d=identicon)[skpassegna](/maintainers/skpassegna)

---

Top Contributors

[![skpassegna](https://avatars.githubusercontent.com/u/91637158?v=4)](https://github.com/skpassegna "skpassegna (8 commits)")

---

Tags

composercomposer-packageipip-lookupip-lookup-apiiplookup-phpipregistrylibrarylookupphpphpsdkIPlookupip-lookupipregistry

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/skpassegna-ipregistry-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/skpassegna-ipregistry-php-sdk/health.svg)](https://phpackages.com/packages/skpassegna-ipregistry-php-sdk)
```

###  Alternatives

[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

553.3M7](/packages/checkout-checkout-sdk-php)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1829.2k2](/packages/huaweicloud-huaweicloud-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
