Giter Site home page Giter Site logo

php-ipaddress's People

Contributors

adamisdumb12384 avatar arjanoosting avatar crwilliams avatar eugenekkh avatar glennpratt avatar leth avatar marcuscobden-nbs avatar peter-gribanov avatar peter279k avatar philipithomas avatar sonarsoftware avatar sstok avatar tabacco avatar thillux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

php-ipaddress's Issues

Required unstable PEAR library

Your documentation claims that PEAR bigint library is optional, but your composer.json requires it. Even more, the version you require is not considered stable, so to install leth/ip-address one needs to explicitly require an unstable version of bigint.

I wanted to submit a pull request making bigint a suggest in composer.json, instead of a require and simply throw exceptions if user tries to access features that require it.

But that would make your library not backwards-compatible with existing clients who have minimum-stability set to dev in their composer.json. Your new version would imply that bigint is no longer required, and if your users do use the functionality, it will suddenly begin throwing exceptions. Of course, clients can easily fix it by adding an explicit require for bigint.

Depending on your attitude towards backwards compatibility this may or may not be an option, what do you think?

Support for extra zeros like in ::factory("192.0.2.001" )

Trying to create an IP with extra zeros in ::factory("192.0.2.01") fails with "Unable to guess IP address type from '192.0.2.01'.".
While that is a somewhat unconventional format, I would still expect it to work.
I have seen some applications where textboxes for ip input will default to a format like 000.000.000.000.

Wrong IP categorization

The IP ::ffff:141.44.23.50 is categorized as IPv4 but it's IPv6.
It seems to be valid (based on http://www.helpsystems.com/intermapper/ipv6-address-validation).
I got the error report from podlove/podlove-publisher#600.

This is (roughly) how I use the library in my code:

<?php
use Leth\IPAddress\IP, Leth\IPAddress\IPv4, Leth\IPAddress\IPv6;

$ip = IP\Address::factory($_SERVER['REMOTE_ADDR']);
if (method_exists($ip, 'as_IPv6_address')) {
    $ip = $ip->as_IPv6_address();
}
$ip_string = $ip->format(IP\Address::FORMAT_COMPACT);

I'm using version 1.0.1 (but the categorization method didn't change in 1.0.2 so I don't think it matters).

Support for php v 8.1

Hi
There is a few issues that prevents proper support for php v 8.1. I have made a fork with minimal changes, but I'd be happy to contribute here. I would then suggest a v 2.0.0 as backwards comparability will be broken. Just writing this issue to test if there is activity in the project.

Inconsistent get_network_start / get_network_end Behavior

Compare these:

$foo = IP\NetworkAddress::factory("127.0.0.1");
$foo->get_cidr(); // 32
$foo->get_network_start(); // Null
$foo->get_network_end(); // Null

$bar = IP\NetworkAddress::factory("127.0.0.1/32");
$bar->get_cidr(); // 32
$bar->get_network_start(); // Not Null
$bar->get_network_start(); // Not Null

For consistent behavior - I think that the network start/end on a single IP should work the same as if it were loaded with a single address CIDR (i.e. 32 for IPv4).

I can work on the code for this, but I'm opening an issue for tracking.

IPv6 address compression not working as expected

Using the following IPv6 address for example

2001:0504:0000:0001:0000:0003:1898:0001

When returning the string representation with it returns this as the compressed address.

2001:504::1:0:3:1898:1

But it should actually be this without compressing the first 0000 hextet in the example. You should only be compressing 2 or more 0000s in a row. Handling One 16-Bit 0 Field - RFC-5952

2001:504:0:1:0:3:1898:1

I believe inet_ntop will return compressed ipv6 address string :)

For example

$ip = IPAddress::factory('2001:0504:0000:0001:0000:0003:1898:0001');

// 2001:504::1:0:3:1898:1
(string) $ip

// 2001:504:0:1:0:3:1898:1
inet_ntop(inet_pton((string) $ip))

IPv6 Addition returns strange results

When using this library for doing ip mathematics ive noticed some strange results.

<?php

error_reporting(E_ALL | E_STRICT);

function autoload($class_name) {
        $file = str_replace('\\', DIRECTORY_SEPARATOR, $class_name);
        $file = str_replace('_', DIRECTORY_SEPARATOR, $file).'.php';
        $local_file = 'classes/'.$file;

        if (file_exists($local_file))
                include_once $local_file;
        else
                include_once $file;
}

spl_autoload_register('autoload');

use Leth\IPAddress\IP, Leth\IPAddress\IPv4, Leth\IPAddress\IPv6;

$ip_addr = 'fc00:1234::df';

$ip = IP\Address::factory($ip_addr);
$ip = $ip->add(1);

echo "IP: ".$ip."\n";

The expected result from this code should be fc00:1234::e0, Yet it returns fc00:1234::

It would be nice to see this fixed as this library is quite helpful.

Why Impl?

This is totally minor.

I'm wondering why you've separated the implementations into Impl classes?

I understand that pattern in Java where you would rather type check against the interface, and the style prefers not naming interfaces IWidget or WidgetInterface.

In PHP land, it's pretty common to name things WidgetInterface and name classes what they are. But here, Impl is an abstract class and there is no interface.

So, just not clear what the extra classes provide.

Address __toString formatting

@essjayhch points out that we are inconsistent in how we format addresses as strings: IPv4 addresses are abbreviated, whereas IPv6 addresses are not.

IPv4 Addresses have two forms, and IPv6 addresses have three:

127.0.0.1
127.000.000.001

::1
0:0:0:0:0:0:0:1
0000:0000:0000:0000:0000:0000:0000:0001

Firstly, we should be consistent in our output.
Secondly, the level of abbreviation should be configurable.

Network merges which result in a duplicate error

An input set of array '0.0.0.0/22', '0.0.0.0/24', '0.0.1.0/24', '0.0.2.0/24', '0.0.3.0/24' should result in '0.0.0.0/22', but instead emits the following error.

1) IP_NetworkAddress_Test::testMerge with data set #12 (array(Leth\IPAddress\IPv4\NetworkAddress Object (...), Leth\IPAddress\IPv4\NetworkAddress Object (...), Leth\IPAddress\IPv4\NetworkAddress Object (...), Leth\IPAddress\IPv4\NetworkAddress Object (...), Leth\IPAddress\IPv4\NetworkAddress Object (...)), array(Leth\IPAddress\IPv4\NetworkAddress Object (...)))
Error: Call to a member function compare_to() on null

/home/.../PHP-IPAddress/classes/Leth/IPAddress/IP/NetworkAddress.php:190
/home/.../PHP-IPAddress/tests/IPNetworkAddressTest.php:519

Patch and test case addition
dupe-merge.txt

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.