• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Useful tools for IP manipulations

PHP IP Tools

Build Status Latest Stable Version Total Downloads Downloads Month License

Universal IP Tools for manipulation on IPv4 and IPv6.

Require this package with Composer

Install this package through Composer. Edit your project's composer.json file to require longman/ip-tools.

Create composer.json file:

{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "longman/ip-tools": "~1.1.0"
    }
}

And run composer update

Or run a command in your command line:

composer require longman/ip-tools

Usage

<?php
$loader = require __DIR__.'/vendor/autoload.php';

use Longman\IPTools\Ip;

// Validating
$status = Ip::isValid('192.168.1.1'); // true

$status = Ip::isValid('192.168.1.256'); // false


// ip2long, long2ip

/// IPv4
$long = Ip::ip2long('192.168.1.1'); // 3232235777

$dec = Ip::long2ip('3232235777'); // 192.168.1.1

/// IPv6
$long = Ip::ip2long('fe80:0:0:0:202:b3ff:fe1e:8329'); // 338288524927261089654163772891438416681

$dec = Ip::long2ip('338288524927261089654163772891438416681', true); // fe80::202:b3ff:fe1e:8329


// Matching

/// IPv4
$status = Ip::match('192.168.1.1', '192.168.1.*'); // true

$status = Ip::match('192.168.1.1', '192.168.*.*'); // true

$status = Ip::match('192.168.1.1', '192.168.*.*'); // true

$status = Ip::match('192.168.1.1', '192.168.0.*'); // false


$status = Ip::match('192.168.1.1', '192.168.1/24'); // true

$status = Ip::match('192.168.1.1', '192.168.1.1/255.255.255.0'); // true

$status = Ip::match('192.168.1.1', '192.168.0/24'); // false

$status = Ip::match('192.168.1.1', '192.168.0.0/255.255.255.0'); // false


$status = Ip::match('192.168.1.5', '192.168.1.1-192.168.1.10'); // true

$status = Ip::match('192.168.5.5', '192.168.1.1-192.168.10.10'); // true

$status = Ip::match('192.168.5.5', '192.168.6.1-192.168.6.10');


$status = Ip::match('192.168.1.1', array('122.128.123.123', '192.168.1.*', '192.168.123.124')); // true

$status = Ip::match('192.168.1.1', array('192.168.123.*', '192.168.123.124'));

/// IPv6

$status = Ip::match('2001:cdba:0000:0000:0000:0000:3257:9652', '2001:cdba:0000:0000:0000:0000:3257:*'); // true

$status = Ip::match('2001:cdba:0000:0000:0000:0000:3257:9652', '2001:cdba:0000:0000:0000:0000:*:*'); // true

$status = Ip::match('2001:cdba:0000:0000:0000:0000:3257:9652',
                    '2001:cdba:0000:0000:0000:0000:3257:1234-2001:cdba:0000:0000:0000:0000:3257:9999'); // true


$status = Ip::match('2001:cdba:0000:0000:0000:0000:3258:9652', '2001:cdba:0000:0000:0000:0000:3257:*'); // false

$status = Ip::match('2001:cdba:0000:0000:0000:1234:3258:9652', '2001:cdba:0000:0000:0000:0000:*:*'); // false

$status = Ip::match('2001:cdba:0000:0000:0000:0000:3257:7778',
                    '2001:cdba:0000:0000:0000:0000:3257:1234-2001:cdba:0000:0000:0000:0000:3257:7777'); // false

This code is available on Github. Pull requests are welcome.

Troubleshooting

If you like living on the edge, please report any bugs you find on the PHP IP Tools issues page.

Contributing

See CONTRIBUTING.md for information.

License

Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.

Credits

Full credit list in CREDITS

More Repositories

1

sublimetext-codeformatter

Code Formatter plugin for ST2/ST3
Python
771
star
2

ubuntu-configuration

Configuration of Debian based OS, such as: Ubuntu, Mint, and Elementary OS
Shell
152
star
3

laravel-lodash

Extra useful functional for Laravel
PHP
93
star
4

sublimetext-stringutilities

Sublime Text 2/3 plugin for string manipulations
Python
83
star
5

sublimetext-autobackups

Sublime Text 2/3 Auto backups plugin
Python
71
star
6

laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x.
PHP
55
star
7

php-geopayment

PHP library for working with Georgian payment providers and banks
PHP
46
star
8

geo-words

Georgian (ka_GE) word list
PHP
18
star
9

php-string-compare

This class compares two strings and outputs the similarities/difference as percentage
PHP
15
star
10

php-code-style

PHP Code style configuration (PHPCS, etc)
PHP
9
star
11

sublimetext-php-package

Sublime Text PHP package updated bundle
8
star
12

dock-php

8
star
13

laravel-platfourm

Laravel Platfourm is a handy tools for creating testable and right architecture applications
PHP
8
star
14

php-ingress-statistics

Class shows graphycal year statistics for Ingress from CSV file
PHP
7
star
15

html-georgian-map

Georgian Map with region highlights and tooltips
HTML
7
star
16

laravel-dummyuser

Dummy user implementation for Laravel 5.x
PHP
6
star
17

sublimetext-material-nil

Minimalist Sublime Text 2/3 UI dark theme and color schemes. Includes HDPI support for retina displays.
JavaScript
5
star
18

python-beautifulsoup

BeautifulSoup fork
Python
5
star
19

akalongman.github.io

SCSS
4
star
20

kautilities

PHP class for convert KA letters to LAT and back
PHP
4
star
21

pear-PHP_Beautifier

PHP_Beautifier modified version
PHP
3
star
22

androidstudio-settings-lp

2
star
23

php-websockets-chat

WebSockets Chat
PHP
2
star
24

phpstorm-settings-lp

2
star
25

linux-longishdark-theme

Longmanish Dark Theme for Linux
CSS
1
star
26

smartthings

SmartThings device types
Groovy
1
star
27

php-geomerchant

PHP Library for Georgian merchants
PHP
1
star
28

php-profiler-library

PHP Library for profiling and debugging
PHP
1
star
29

ansistrano

1
star
30

android-helloworld

Android Hello World with best practices
Java
1
star