All Projects → S1lentium → Iptools

S1lentium / Iptools

Licence: mit
PHP Library for manipulating network addresses (IPv4 and IPv6)

Projects that are alternatives of or similar to Iptools

Ineter
Fast Java library for working with IP addresses, ranges, and subnets
Stars: ✭ 39 (-76.07%)
Mutual labels:  network, networking, ipv6, ipv4, subnet
Netaddr
A network address manipulation library for Python
Stars: ✭ 648 (+297.55%)
Mutual labels:  networking, ipv6, ipv4, subnet
Ship
A simple, handy network addressing multitool with plenty of features
Stars: ✭ 81 (-50.31%)
Mutual labels:  networking, ipv6, ip, ipv4
freebind
IPv4 and IPv6 address rate limiting evasion tool
Stars: ✭ 88 (-46.01%)
Mutual labels:  ipv6, ipv4, subnet
ip
Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.
Stars: ✭ 212 (+30.06%)
Mutual labels:  ipv6, ipv4, ip
Aggregator
A stand-alone class implementation of the IPv4+IPv6 IP+CIDR aggregator from CIDRAM.
Stars: ✭ 19 (-88.34%)
Mutual labels:  ipv6, ipv4, ip
captcp
A open source program for TCP analysis of PCAP files
Stars: ✭ 110 (-32.52%)
Mutual labels:  ipv6, ipv4, ip
Pytricia
A library for fast IP address lookup in Python.
Stars: ✭ 140 (-14.11%)
Mutual labels:  networking, ipv6, ipv4
Valvesockets Csharp
Managed C# abstraction of GameNetworkingSockets library by Valve Software
Stars: ✭ 273 (+67.48%)
Mutual labels:  networking, ipv6, ipv4
Dsnet
Simple command to manage a centralised wireguard VPN. Think wg-quick but quicker: key generation + address allocation.
Stars: ✭ 365 (+123.93%)
Mutual labels:  networking, ipv6, ipv4
Cnp3
Computer Networking : Principles, Protocols and Practice (first and second edition, third edition is being written on https://github.com/cnp3/ebook)
Stars: ✭ 471 (+188.96%)
Mutual labels:  networking, ipv6, ip
Php Ip Tools
Useful tools for IP manipulations
Stars: ✭ 152 (-6.75%)
Mutual labels:  ipv6, ip, ipv4
Geolocate-IP-Browser-Extension
A browser extension, which shows you the origin of your IP address.
Stars: ✭ 21 (-87.12%)
Mutual labels:  ipv6, ipv4, ip
bacnet-stack
BACnet Protocol Stack library provides a BACnet application layer, network layer and media access (MAC) layer communications services.
Stars: ✭ 199 (+22.09%)
Mutual labels:  ipv6, ipv4, ip
Ip
🌏根据IpV4、IpV6地址获取定位信息的PHP🐘组件 PHP components that obtain location information based on IpV4, IpV6 addresses
Stars: ✭ 23 (-85.89%)
Mutual labels:  ipv6, ipv4, ip
PHP-IPAddress
IP Address utility classes for PHP
Stars: ✭ 63 (-61.35%)
Mutual labels:  ipv6, ipv4, subnet
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 (+69.33%)
Mutual labels:  ipv6, ipv4, subnet
private-ip
Check if IP address is private.
Stars: ✭ 26 (-84.05%)
Mutual labels:  ipv6, ipv4, ip
go-external-ip
a Golang library to get your external ip from multiple services
Stars: ✭ 55 (-66.26%)
Mutual labels:  ipv6, ipv4, ip
Enet Csharp
Reliable UDP networking library
Stars: ✭ 464 (+184.66%)
Mutual labels:  networking, ipv6, ipv4

IPTools

PHP Library for manipulating network addresses (IPv4 and IPv6).

Build Status Coverage Status Code Climate

PHP 5.4 PHP 7.0

Installation

Composer: Run in command line:

composer require s1lentium/iptools

or put in composer.json:

{
    "require": {
        "s1lentium/iptools": "*"
    }
}

Usage

IP Operations

$ip = new IP('192.168.1.1');
echo $ip->version;// IPv4
$ip = new IP('fc00::');
echo $ip->version; // IPv6

Parsing IP from integer, binary and hex:

echo (string)IP::parse(2130706433); // 127.0.0.1
echo (string)IP::parse('0b11000000101010000000000100000001') // 192.168.1.1
echo (string)IP::parse('0x0a000001'); // 10.0.0.1

or:

echo (string)IP::parseLong(2130706433); // 127.0.0.1
echo (string)IP::parseBin('11000000101010000000000100000001'); // 192.168.1.1
echo (string)IP::parseHex('0a000001'); // 10.0.0.1

Converting IP to other formats:

echo IP::parse('192.168.1.1')->bin // 11000000101010000000000100000001
echo IP::parse('10.0.0.1')->hex // 0a000001
echo IP::parse('127.0.0.1')->long // 2130706433

Other public properties:

maxPrefixLength The max number of bits in the address representation: 32 for IPv4, 128 for IPv6.

octetsCount The count of octets in IP address: 4 for IPv4, 16 for IPv6

reversePointer The name of the reverse DNS PTR for the address:

echo new IP::parse('192.0.2.5')->reversePointer // 5.2.0.192.in-addr.arpa
echo new IP::parse('2001:db8::567:89ab')->reversePointer // b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa

Network Operations

echo Network::parse('192.0.0.1 255.0.0.0')->CIDR; // 192.0.0.0/8
echo (string)Network::parse('192.0.0.1/8')->netmask; // 255.0.0.0
echo (string)Network::parse('192.0.0.1'); // 192.0.0.1/32

Exclude IP from Network:

$excluded = Network::parse('192.0.0.0/8')->exclude(new IP('192.168.1.1'));
foreach($excluded as $network) {
	echo (string)$network . '<br>';
}
192.0.0.0/9
192.128.0.0/11
192.160.0.0/13
192.168.0.0/24
192.168.1.0/32
192.168.1.2/31
...
192.192.0.0/10

Exclude Subnet from Network:

$excluded = Network::parse('192.0.0.0/8')->exclude(new Network('192.168.1.0/24'));
foreach($excluded as $network) {
	echo (string)$network . '<br>';
}
192.0.0.0/9
192.128.0.0/11
192.160.0.0/13
192.168.0.0/24
192.168.2.0/23
...
192.192.0.0/10

Split network into equal subnets

$networks = Network::parse('192.168.0.0/22')->moveTo('24');
foreach ($networks as $network) {
	echo (string)$network . '<br>';
}
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24

Iterate over Network IP adresses:

$network = Network::parse('192.168.1.0/24');
foreach($network as $ip) {
	echo (string)$ip . '<br>';
}
192.168.1.0
...
192.168.1.255

Get Network hosts adresses as Range:

$hosts = Network::parse('192.168.1.0/24')->hosts // Range(192.168.1.1, 192.168.1.254);
foreach($hosts as $ip) {
	echo (string)$ip . '<br>';
}
192.168.1.1
...
192.168.1.254

Count Network IP adresses

echo count(Network::parse('192.168.1.0/24')) // 254

Range Operations

Define the range in different formats:

$range = new Range(new IP('192.168.1.0'), new IP('192.168.1.255'));
$range = Range::parse('192.168.1.0-192.168.1.255');
$range = Range::parse('192.168.1.*');
$range = Range::parse('192.168.1.0/24');

Check if IP is within Range:

echo Range::parse('192.168.1.1-192.168.1.254')->contains(new IP('192.168.1.5')); // true
echo Range::parse('::1-::ffff')->contains(new IP('::1234')); // true

Iterate over Range IP adresses:

$range = Range::parse('192.168.1.1-192.168.1.254');
foreach($range as $ip) {
	echo (string)$ip . '<br>';
}
192.168.1.1
...
192.168.1.254

Get Networks that fit into a specified range of IP Adresses:

$networks = Range::parse('192.168.1.1-192.168.1.254')->getNetworks();

foreach($networks as $network) {
	echo (string)$network . '<br>';
}
192.168.1.1/32
192.168.1.2/31
192.168.1.4/30
192.168.1.8/29
192.168.1.16/28
192.168.1.32/27
192.168.1.64/26
192.168.1.128/26
192.168.1.192/27
192.168.1.224/28
192.168.1.240/29
192.168.1.248/30
192.168.1.252/31
192.168.1.254/32

Count IP adresses in Range

echo count(Range::parse('192.168.1.1-192.168.1.254')) // 254

License

The library is released under the MIT.

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].