S
S
stikname2014-01-11 23:43:05
PHP
stikname, 2014-01-11 23:43:05

How to get a list of networks from the IP range in php?

Please tell me a php solution to translate a range of addresses into a network with a mask.

For example:

80.75.133.0-80.75.135.127


Translate to:
80.75.133.0/24
80.75.134.0/24
80.75.135.0/25


As an example, I can show the following site:
ip-calculator.ru

The second option is "Get a list of networks"

I can make requests to it through the same curl and translate the ranges I need in the networks with a mask, then parse them, but this is a terrible crutch :) I would like to find a solution to do this in my script.

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-01-12
Protko @Fesor


Consider an example of writing a range of IP addresses in the form 10.96.0.0/11. In this case, the subnet mask will have the binary form 11111111 11100000 00000000 00000000, or the same in decimal: 255.224.0.0. 11 bits of the IP address are assigned to the network number, and the remaining 32 - 11 = 21 bits of the full address - to the local address in this network. In total, 10.96.0.0/11 means the address range from 10.96.0.1 to 10.127.255.255.
did you read this?
www.php.net/manual/en/ref.network.php#75922

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question