SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    aggregating ip list

    Hello

    I have a large ip list file for example

    127.0.0.1
    127.0.0.12
    127.0.0.1
    127.0.0.234
    127.0.0.1
    127.0.0.13
    127.0.0.1
    128.1.4.2
    127.0.0.14

    I would aggregate adiacent ip addresses , for example the file list should be converted in this way

    127.0.0.1
    127.0.0.12 - 127.0.0.14
    127.0.0.1
    127.0.0.234
    127.0.0.1
    127.0.0.1
    128.1.4.2


    Anyone can suggest me which is the fast way and less cpu intensive to do this operation with php ?

    Thank you
    trcris ::> http://www.trcris.com

  2. #2
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    less cpu intensive than what?

    My first idea would be to read the file content (assuming it is on a file), splitting by line breaks and sorting it.

    Then you can compare each adjacent pairs (remove the dots and do a simple subtraction)

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about

    127.0.0.998
    127.0.0.999
    127.0.1.0

    Should all three be aggregated, or just two?

    My first thought would be a pretty memory instensive method, but I think it would be pretty cpu and disk efficient.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •