All Projects → leth → PHP-IPAddress

leth / PHP-IPAddress

Licence: other
IP Address utility classes for PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to PHP-IPAddress

Ipaddress
Java library for handling IP addresses and subnets, both IPv4 and IPv6
Stars: ✭ 197 (+212.7%)
Mutual labels:  ipv6, ipv4, ip-address, subnet
Geolocate-IP-Browser-Extension
A browser extension, which shows you the origin of your IP address.
Stars: ✭ 21 (-66.67%)
Mutual labels:  ipv6, ipv4, ip-address, ipv6-address
freebind
IPv4 and IPv6 address rate limiting evasion tool
Stars: ✭ 88 (+39.68%)
Mutual labels:  ipv6, ipv4, subnet, ipv6-address
private-ip
Check if IP address is private.
Stars: ✭ 26 (-58.73%)
Mutual labels:  ipv6, ipv4, ip-address
node-ip2region
IP/IPv6 to region on Node.js (IP/IPv6 地址到区域运营商)
Stars: ✭ 95 (+50.79%)
Mutual labels:  ipv6, ip-address, ipv6-address
geoip
🌚 🌍 🌝 GeoIP 规则文件加强版,同时支持定制 V2Ray dat 格式路由规则文件 geoip.dat 和 MaxMind mmdb 格式文件 Country.mmdb。Enhanced edition of GeoIP files for V2Ray, Xray-core, Trojan-Go, Clash and Leaf, with replaced CN IPv4 CIDR available from ipip.net, appended CIDR lists and more.
Stars: ✭ 524 (+731.75%)
Mutual labels:  ipv6, ipv4, ipv6-address
IP2Location-PHP-Module
This module is a PHP module that enables the user to find the country, region, city, coordinates, zip code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, mobile, usage types, address type, IAB category, etc that any IP address or host name originates from.
Stars: ✭ 154 (+144.44%)
Mutual labels:  ipv6, ipv4, ip-address
php-ip-anonymizer
IP address anonymizer library for PHP
Stars: ✭ 55 (-12.7%)
Mutual labels:  ipv6, ipv4, ip-address
Ipwhois
Retrieve and parse whois data for IPv4 and IPv6 addresses
Stars: ✭ 432 (+585.71%)
Mutual labels:  ipv6, ipv4, ip-address
Ineter
Fast Java library for working with IP addresses, ranges, and subnets
Stars: ✭ 39 (-38.1%)
Mutual labels:  ipv6, ipv4, subnet
Ip Num
A TypeScript/JavaScript library for working with ASN, IPv4, and IPv6 numbers. It provides representations of these internet protocol numbers with the ability to perform various IP related operations like parsing, validating etc. on them
Stars: ✭ 113 (+79.37%)
Mutual labels:  ipv6, ipv4, ip-address
Iptools
PHP Library for manipulating network addresses (IPv4 and IPv6)
Stars: ✭ 163 (+158.73%)
Mutual labels:  ipv6, ipv4, subnet
ip
Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.
Stars: ✭ 212 (+236.51%)
Mutual labels:  ipv6, ipv4, ip-address
Ipnetwork
IPNetwork command line and C# library take care of complex network, IP, IPv4, IPv6, netmask, CIDR, subnet, subnetting, supernet, and supernetting calculation for .NET developers. It works with IPv4 as well as IPv6, is written in C#, has a light and clean API, and is fully unit-tested
Stars: ✭ 276 (+338.1%)
Mutual labels:  ipv6, ipv4, subnet
fakeroute
IPv4 and IPv6 traceroute fake hop generator through IP spoofing
Stars: ✭ 75 (+19.05%)
Mutual labels:  ipv6, ipv4, ipv6-address
Netaddr
A network address manipulation library for Python
Stars: ✭ 648 (+928.57%)
Mutual labels:  ipv6, ipv4, subnet
ipapi-python
Python bindings for https://ipapi.co (IP Address Location) - Use with python / django / flask for IP address location lookup
Stars: ✭ 42 (-33.33%)
Mutual labels:  ipv6, ipv4, ip-address
ipaddress
Data analysis of IP addresses and networks
Stars: ✭ 20 (-68.25%)
Mutual labels:  ipv6, ipv4, ip-address
Ipnetwork
A library to work with CIDRs in rust
Stars: ✭ 64 (+1.59%)
Mutual labels:  ipv6, ipv4, ip-address
IPpy
🚀 Ping IP addresses and domains in parallel to find the accessible and inaccessible ones.
Stars: ✭ 54 (-14.29%)
Mutual labels:  ipv6, ipv4, ip-address

PHP-IPAddress

A set of utility classes for working with IP addresses in PHP. Supports both IPv4 and IPv6 schemes.

Requirements

  • PHP version 5.3.0 or greater.

  • The PEAR Math_BigInteger class

    Required for add & subtract operations on IPv6 addresses, and finding IPs in IPv6 address blocks.

Examples

<?php
use Leth\IPAddress\IP, Leth\IPAddress\IPv4, Leth\IPAddress\IPv6;
// Creates an instance
$ip = IP\Address::factory('127.0.0.1');

// Prints "127.0.0.1"
echo $ip . "\n";

/**
 * IP\Address::factory(...) will attempt to guess the address version from the arguments
 */
// Returns an instance of IPv4\Address
$ip = IP\Address::factory('127.0.0.1');
$ip = IPv4\Address::factory('127.0.0.1');

// Returns an instance of IPv6\Address
$ip = IP\Address::factory('::1');
$ip = IPv6\Address::factory('::1');

/**
 * IP\NetworkAddress::factory(...) will also attempt to guess protocol versions
 */
// Can either be called with the subnet size encoded in the address string,
$net_addr = IP\NetworkAddress::factory('192.168.0.1/24');
// Or as the second parameter
$net_addr = IP\NetworkAddress::factory('192.168.0.1', 24);

// Prints '192.168.0.0'
echo $net_addr->get_network_address() . "\n";
// Prints '192.168.0.255'
echo $net_addr->get_broadcast_address() . "\n";
// Prints '255.255.255.0'
echo $net_addr->get_subnet_mask() . "\n";

/**
 * For each address of the specified network.
 */
$network = IPv4\NetworkAddress::factory('192.168.0.0/24');
foreach ($network as $ip) {
	// $ip is instance of IPv4\Address with value:
	// 192.168.0.0
	// 192.168.0.1
	// ...
}

$network = IPv4\NetworkAddress::factory('192.168.0.0/24');
// Prints '256'
echo count($network);

/**
 * Merge adjacent NetworkAddress blocks into larger blocks
 */
$small = array(
	IPv4\NetworkAddress::factory('192.168.0.0/24'),
	IPv4\NetworkAddress::factory('192.168.1.0/24')
);
$merged = IP\NetworkAddress::merge($small);
// Prints '1'
echo count($merged);
// Prints '1'
echo $merged[0] == IP\NetworkAddress::factory('192.168.0.0/23');

/**
 * Get specified octet from IP
 */
$ipv4 = IP\Address::factory('192.168.1.102');
// Prints '102'
echo $ipv4->get_octet(-1);
// Prints '168'
echo $ipv4[1];

$ipv6 = IP\Address::factory('2490::fa');
// Prints '250'
echo $ipv6->get_octet(-1);
// Prints '0'
echo $ipv6[5];

Test Cases

To run the test cases, the following commands will do the trick:

  • No-frills tests:

    phpunit -c phpunit.xml.dist

  • Generate code coverage reports into './coverage/':

    phpunit -c phpunit.xml.dist --coverage-html coverage

  • With colours and verbose output:

    phpunit -c phpunit.xml.dist --colors --verbose

  • All together:

    phpunit -c phpunit.xml.dist --coverage-html coverage --colors --verbose

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].