Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (28) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2021-05-17 (3 months ago) | Not yet rated by the users | Total: 24 | All time: 10,325 This week: 259 |
Version | License | PHP version | Categories | |||
ipv4-address-convert 1.0 | Custom (specified... | 5 | Networking, PHP 5, Conversion |
Description | Author | ||||||||||||||
This package can convert formats of IPv4 network addresses. |
|
This PHP package allows you to perform IPv4 Address conversion within Laravel applications.
The package accepts an IP address as an input and converts it to a specified IP address format. The input and output can be one of these formats: binary string, dotted decimal, hexadecimal string, or long integer
Converts from:
Converts to:
You can install the package via composer and then publish the assets:
Add the library to your composer.json file:
{
"require": {
"acamposm/ipv4-address-converter": "^1.0"
}
}
Or use composer to install the library:
composer require acamposm/ipv4-address-converter
*Note:* We try to follow SemVer v2.0.0.
These are the valid input methods for the conversion of the IP Addresses.
Set the input for the IP Address conversion as a binary string.
| accepts | string
$address |
| --- | --- |
| returns | IPv4AddressConverter |
Set the input for the IP Address conversion as a doted decimal string.
| accepts | string
$address |
| --- | --- |
| returns | IPv4AddressConverter |
Set the input for the IP Address conversion as a hexadecimal string.
| accepts | string
$address |
| --- | --- |
| returns | IPv4AddressConverter |
Set the input for the IP Address conversion as a long integer.
| accepts | string
$address |
| --- | --- |
| returns | IPv4AddressConverter |
These methods are valid output methods for the conversion of the IP address specified in the previous input methods.
Set binary string as desired output format.
Set dotted decimal as desired output format.
Set hexadecimal string as desired output format.
Set long integer as desired output format.
With these modifiers we can control the output of the conversion operation.
This modifier will apply dot notation to the output of the conversion, only available to binary strings and hexadecimal strings.
This example shows how to convert a dotted-decimal IP address to a long integer IP address.
use Acamposm\IPv4AddressConverter\IPv4AddressConverter;
$converter = IPv4AddressConverter::convert()
->fromDecimal('192.168.10.254')
->toLong()
->get();
var_dump($converter);
The output of the conversion is a integer.
int(3232238334)
This example shows how to convert a dotted decimal IP address to binary string IP address.
use Acamposm\IPv4AddressConverter\IPv4AddressConverter;
$converter = IPv4AddressConverter::convert()
->fromDecimal('192.168.10.254')
->toBinary()
->get();
var_dump($converter);
The output is a binary string IP Address.
string(32) "11000000101010000000101011111110"
This example shows how to convert a dotted-decimal IP address to binary string IP address with dot notation.
use Acamposm\IPv4AddressConverter\IPv4AddressConverter;
$converter = IPv4AddressConverter::convert()
->fromDecimal('192.168.10.254')
->toBinary()
->withDotNotation()
->get();
var_dump($converter);
The output is a binary string IP Address with dot notation.
string(35) "11000000.10101000.00001010.11111110"
This example shows how to convert a dotted-decimal IP address to a hexadecimal string IP address.
use Acamposm\IPv4AddressConverter\IPv4AddressConverter;
$converter = IPv4AddressConverter::convert()
->fromDecimal('192.168.10.254')
->toHexadecimal()
->get();
var_dump($converter);
The output of the conversion is a hexadecimal string IP address.
string(8) "C0A80AFE"
This example shows how to convert a dotted-decimal IP address to a hexadecimal string IP address with dot notation.
use Acamposm\IPv4AddressConverter\IPv4AddressConverter;
$converter = IPv4AddressConverter::convert()
->fromDecimal('192.168.10.254')
->toHexadecimal()
->withDotNotation()
->get();
var_dump($converter);
The output of the conversion is a hexadecimal string IP address with dot notation.
string(11) "C0.A8.0A.FE"
There's an all method, that converts an input address to all formats. The input address for the conversion can be a binary, decimal, hexadecimal or long address.
use Acamposm\IPv4AddressConverter\IPv4AddressConverter;
$converter = IPv4AddressConverter::convert()
->fromDecimal('192.168.10.254')
->withDotNotation()
->all();
var_dump($converter);
The output is an object with the address converted to all formats.
object(stdClass)#638 (4) {
["binary"] =>
string(35) "11000000.10101000.00001010.11111110"
["decimal"] =>
string(14) "192.168.10.254"
["hexadecimal"] =>
string(11) "C0.A8.0A.FE"
["long"] =>
int(3232238334)
}
To run the tests you only need to run this command:
composer test
Please see CHANGELOG.md for more information what has changed recently.
Thank you for considering contributing to the improvement of the package. Please see CONTRIBUTING.md for details.
If you discover any security related issues, please send an e-mail to Angel Campos via angel.campos.m@outlook.com instead of using the issue tracker. All security vulnerabilities will be promptly addressed.
The php package IPv4 Address Converter, comply with the next standards:
Angel Campos
The package IPv4 Address Converter is an open-source package and is licensed under The MIT License (MIT). Please see License File for more information.
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file, 7 directories) | ||||
tests (6 files) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
.styleci.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
CODE_OF_CONDUCT.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONTRIBUTING.md | Data | Auxiliary data | ||
LICENSE.md | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
SECURITY.md | Data | Auxiliary data |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Converters (5 files) | ||||
Enums (1 file) | ||||
Exceptions (1 file) | ||||
Facades (1 file) | ||||
Interfaces (1 file) | ||||
ServiceProviders (1 file) | ||||
Traits (1 file) | ||||
IPv4AddressConverter.php | Class | Class source |
Files | / | src | / | Converters |
File | Role | Description |
---|---|---|
BaseAddressConverter.php | Class | Class source |
BinaryIPv4AddressConverter.php | Class | Class source |
DecimalIPv4AddressConverter.php | Class | Class source |
HexadecimalIPv4AddressConverter.php | Class | Class source |
LongIPv4AddressConverter.php | Class | Class source |
Files | / | src | / | ServiceProviders |
File | Role | Description |
---|---|---|
IPv4AddressConverterServiceProvider.php | Class | Class source |
Files | / | tests |
File | Role | Description |
---|---|---|
BaseTestCase.php | Class | Class source |
GetAddressesFromBinaryStringTest.php | Class | Class source |
GetAddressesFromDecimalStringTest.php | Class | Class source |
GetAddressesFromHe...cimalStringTest.php | Class | Class source |
GetAddressesFromLongIntegerTest.php | Class | Class source |
InstanceTest.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.