9 Replies Latest reply on Oct 22, 2013 1:06 PM by ecklerwr1

    IP Address Sorting


      I am the only person that would like to have displays that "sort by IP address" to actually sort by the IP address in numerical order instead of by the alpha value of the address?

      In what world is this sequence "sorted"




        • Re: IP Address Sorting

          Where do you see this problem? When you export it?


          If so, put in a feature request to request that the last octet is 3 digits long e.e.

          • Re: IP Address Sorting

            You aren't the only one.  I had hoped that sorting on IPAddressGUID would work, and it does, but only if the group you're sorting on is all in a . subnet.  If you have larger groups, they still interleave but now on the third octet rather than the fourth octet, which is even worse.


            In perl apps we routinely sort by proper IP by using the Socket module thusly:


            use Socket;

            sub a2int {

              $ip_int = unpack('N',inet_aton(shift));  # convert string into a native perl integer


            sub int2a {

              $ip_asc = inet_ntoa(pack('N', shift ));  #convert native perl integer back into ascii dot notation



            # Assuming @unsorted contains a perl hash of Node objects gleaned from Orion.Nodes, including field IPAddress, then:


            @sorted = map  { $_->[0] }

               sort { $a->[1] <=> $b->[1] } # use numeric comparison

               map  { [$_, &a2int($_->{IPAddress})] }   # calculate the length of the string




            (The sort above is a Schwartzian transform - Wikipedia, the free encyclopedia )


            I may do something like this by adding a new custom property to store a converted a2int value for the duration of an swql query, using some sort of batch update to pre-compute the thing.  The trouble is, nodes change IPs often enough that I'd have to re-compute the CP every time I used it or the results won't be trustworthy. 


            It would be easier if there was simply an a2int() equivalent function in SWQL itself, or if the IPAddressGUID thing produced a sortable, trustworthy result.

            • Re: IP Address Sorting

              This has always been a problem... its just what happens when you use a normal sort on IP addr's just like it would sort in excel.  I also agree a fix has to be for all the way to class A... NOT just for class C and work on VLSM's.