On Thu, 23 Aug 2001 12:58, Chris Aitken wrote:
Hi all,
Just a quick one,
I am pulling a whole Class C list of IP addresses, and im trying to
sort them in order, but im getting it displayed
127.0.0.1
127.0.0.10
127.0.0.100
127.0.0.101
127.0.0.102
etc. Is there any other way to sort
And if the numbers are from different subnets, you could sort like so
(assuming addresses are in a 1-dimensional array, here called
$IpAddresses):
function sort_address($IpAddresses) {
$List = array();
foreach ($IpAddresses as $A) {
list($x,$y,$z,$t) = explode('.', $A);
one solution that works on all ip numbers
?
$ip =
array(192.168.132.3,192.168.132.2,0.0.0.1,192.168.132.4,192.168.1.1,192.168.0.1);
foreach($ip as $val){
$split = explode(.,$val);
$num = (16777216 * $split[0]) + (65536 * $split[1]) + (256 *
$split[2]) + $split[3];
Hi all,
Just a quick one,
I am pulling a whole Class C list of IP addresses, and im trying to sort
them in order, but im getting it displayed
127.0.0.1
127.0.0.10
127.0.0.100
127.0.0.101
127.0.0.102
etc. Is there any other way to sort this thinking they are numbers, rather
than text ?
Chris,
What order are you trying to achieve? These look to be in order?
Chris
Chris Aitken wrote:
Hi all,
Just a quick one,
I am pulling a whole Class C list of IP addresses, and im trying to sort
them in order, but im getting it displayed
127.0.0.1
127.0.0.10
127.0.0.100
Chris,
Understand the problem now.
All you need to keep is the last octect of the IP Address.
The following code snippet generates an array entry for each ip. The array is
then sorted and the result prepended with the base IP.
?
$strBaseIP = 127.0.0.;
for ($i=0;$i=255;$i++) {
$strIP
6 matches
Mail list logo