Getting list IPs from CIDR notation in PHP

前端 未结 13 1359
慢半拍i
慢半拍i 2020-12-08 05:38

Is there a way (or function/class) to get the list of IP addresses from a CIDR notation?

For example, I have 73.35.143.32/27 CIDR and want to get the list of all IP\

13条回答
  •  醉酒成梦
    2020-12-08 05:59

    Highly recommend this PHP Lib: https://github.com/S1lentium/IPTools

    It can manipulate network easily with many functions.

    e.g. Iterate over Network IP adresses:

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

提交回复
热议问题