Create php list of valid ips for a mysql table

Asked

Viewed 95 times

0

Good morning guys, I need to create a list of valid ips from my network. I have 15 class A subnets. That is, my network is 10.5.5.0 until 10.5.20.255. I was thinking something like: $IP for (i=1; i<255; i++) do $IP.$i However, in this logic, I would only create class C ips. This list would be inserted into a mysql table. I await suggestions.

1 answer

0

$ip = '10.5.';
for ($redeB=5; $redeB < 21 ; $redeB++) { 
    for ($redeC=1; $redeC < 255; $redeC++) { 
        echo $ip.$redeB.'.'.$redeC.'<br>';
    }
}

The first is to tell rede B, the second is to tell rede C. The first is account of 5 ~ 20, inside of for put another for 1 ~ 254, every network B the second for will count from 1 ~ 254.

  • Thank you very much Luis. I understand the logic. But how can I generate this for a INSERT in a mysql table?

  • Using PDO(recommended):http://php.net/manual/en/book.pdo.php Or mysqli: https://secure.php.net/manual/en/book.mysqli.php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.