Hi, I know I can do this easily by converting the IP addresses to decimal notation first using PHP built in functions like up2long
and long2ip
. I just want to be able to do the same using the standard IP address notation as an exercise.
The problem I am thinking goes like this: Given an starting IP address, say 192.168.1.100, and an ending IP address, say 201.130.22.10. Make the program that prints all the address numbers in that range (192.168.1.100, 192.168.1.101, … , 201.130.22.9, 201.130.22.10).
I was thinking that maybe the way to go would be to make a nested for
loop inside a while
condition until the first octet of the starting address matches the first octet of the ending address. Then execute the same block of code for the second octet and so on until the program reaches the ending address and finished.
I just started learning to program recently so it is quite possible that my of thinking and or writing code is far from elegant. If you were to this, how would you do it?