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

    IP Address Sorting

    twgraham

      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"

       

      10.1.1.1

      10.1.1.100

      10.1.1.2

       

      ???

        • Re: IP Address Sorting
          superfly99

          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. 10.1.1.001

          • Re: IP Address Sorting
            joiellis

            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 .255.255.255.0 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

               @unsorted;

             

             

            (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
              ecklerwr1

              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.