Ordereing an IP address

  • Casting to an INT should actually run a bit faster over a large number of rows.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • yeah,

    I have a table of called tbl_Router_details with stuff like IP, subnet, etc,

    another table with router configs,

    another table with router locations etc

    these are all inner joined.

    When I write out all the data to an ASP, I have the headers as clickable events that order by that column, on each click, i've written it to build a new query based on what the sort order needs to be by,

    Now for the fun bit, :o)

    I'm going to write a function in a DLL to telnet the routers and upload / download the configs and store in a separate table.

  • hi

    IP address (IPV4) is divided into four sub-blocks. Each sub-block has a different weight number, each powered by 256. The IP number is being used in the database because it is efficient to search between a range of numbers in the database.

    The beginning IP number and the ending IP number are calculated based on the following formula:

    Collapse

    IP Number = 16777216*w + 65536*x + 256*y + z (1)

    where:

    Collapse

    IP Address = w.x.y.z

    For example, if the IP address is "202.186.13.4", then its IP number is "3401190660" based on the above formula.

    Collapse

    IP Address = 202.186.13.4

    So, w = 202, x = 186, y = 13 and z = 4

    IP Number = 16777216*202 + 65536*186 + 256*13 + 4

    = 3388997632 + 12189696 + 3328 + 4

    = 3401190660

    To reverse the IP number to the IP address:

    Collapse

    w = int ( IP Number / 16777216 ) % 256

    x = int ( IP Number / 65536 ) % 256

    y = int ( IP Number / 256 ) % 256

    z = int ( IP Number ) % 256

    you can get the ip address and also the number format geo location from ip-details.com[/url]

  • That's cool... so, are you suggesting a method sort IP addresses that aren't necessarily in the 3 digit byte format?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 4 posts - 16 through 18 (of 18 total)

You must be logged in to reply to this topic. Login to reply