Web Hosting Info

Search:

featured partner

The IP to Country Database

Handbook

IP Number
Last updated by amit on Thu, 09/25/2003 - 06:25
The IP_FROM and IP_TO fields of the IP-to-Country Database are numeric representations of the dotted IP address.


The formula to convert an IP Address of the form A.B.C.D to an IP Number is:
IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D
Which is the same as:
IP Number = A x 16777216 + B x 65536 + C x 256 + D


In PHP 4 you can use the following to convert a dotted IP Address to its corresponding IP Number:
$ip_number = sprintf("%u", ip2long($dotted_ip_address));

and this to convert IP Number to its corresponding dotted IP Address:
$dotted_ip_address = long2ip($ip_number);
    Comment viewing options:
    Select your preferred way to display the comments and click 'Save settings' to submit your changes.
    Dotted ip -> 4 byte int conversion
    Posted by tanderson on Mon, 07/21/2003 - 23:16.
    Alternatively, if you're using MySQL you can use the functions inet_ntoa() and inet_aton() for converting to and from dotted representation respectively.
    For example:
    SELECT country_name FROM iptocountry
      WHERE inet_aton('$remote_addr') >= ip_from
      AND inet_aton('$remote_addr') <= ip_to;
    
     
    How to convert IPaddress to Dotted address in MS SQL Server 2000
    Posted by dhiraj on Thu, 10/16/2003 - 19:46.
    Is there is similar function for Microsoft SQL Server to convert the IP adress to Dotted IP?
    Dhiraj Sharma
    Dotted ip to number conversion with bit shifting
    Posted by vinay on Tue, 07/22/2003 - 08:36.
    The dotted ip to number conversion with bit shifting
    Example
    $ip = "194.109.136.80";
    $ip_bytes = explode(".", $ip);
    $longnum = ($ip_bytes[0] << 24) | ($ip_bytes[1] << 16) |
               ($ip_bytes[2] << 8) | $ip_bytes[3];
    printf("%u\n", $longnum);
    
    Just another way of doing it ;)
    Reverse IP to number formula
    Posted by daryabeygi on Fri, 12/12/2003 - 00:19.
    with 256 as our base multiplier, I will restate:
    IP Number = A * m^3 + B * m^2 + C * m^1 + D * m^0

    beautifully,
    A = (IP Number / m^3) - Modulo(IP Number / m^3)

    In words, devide the IP number by the multiplier for the octet you wish to retrieve and throw away the remainder.

    Then reapply the multiplier to your result and subtract that result from the IP number before calculating the next octet.

    wash, rinse, repeat....

    and D. Sharma, if you can't make use of this, there are inet_aton and inet_ntoa in the wsock32.dll. You should be able to make use of them in MS SQL server through either DTS or extended procedures.....
    Getting Actual IP Number in case of Integer Overflow
    Posted by anupam on Fri, 04/23/2004 - 08:15.
    Its good to use ip2long() function to get the IP Number. I any case, if you get a negative number as the result of ip2long(), what will you do? Here is a solution in PHP :

    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $ip_number = sprintf("%u", ip2long($ip));

    here goes your own code......
    ?>

    I think it will help you.
    A vbscript and Excel ways to convert number to ip
    Posted by carlop on Thu, 01/12/2006 - 07:10.
    Hi, if this can help someone a vbscript (Visual Basic Scripting Edition) long2ip function I have wrote.
    function vbLong2ip(ipLong)
    	ipLong = abs(ipLong)
    	ipA = fix(ipLong/256^3)
    	ipB = fix((ipLong-ipA*256^3)/256^2)
    	ipC = fix((ipLong-(ipA*256^3+ipB*256^2))/256)
    	ipD = fix(ipLong-((ipA*256^3)+(ipB*256^2)+(ipC*256)))
    	vbLong2ip=ipA & "." & ipB & "." & ipC & "." & ipD
    end function
    
    and with Excel you can do :
    (with A1 = IP Number)
    B1 = FLOOR (A1/256^3;1)
    C1 = FLOOR ((A1-B1*256^3)/256^2;1)
    D1 = FLOOR ((A1-(B1*256^3+C1*256^2))/256;1)
    E1 = FLOOR ((A1-((B1*256^3)+(C1*256^2)+D1*256));1)
    F1 = B1 & "." & C1 & "." & D1 & "." & E1
    
    you will then have in Excel sheet :
     |     A     |     B    |    C     |     D    |    E     |   F        
    -----------------------------------------------------------
    1| IP number | ipA part | ipB part | ipC part | ipD part | IP Address (A.B.C.D)
    
    of course all this can be write in others ways (by concatenating all formulas on one line) in both vbscript or excel ...
    cheers
    CP aka ECL
    Python version
    Posted by afoo on Fri, 03/09/2007 - 16:01.
    thought i'd share this, maybe it's of use to someone else, too.
    def num2dot(c):
        assert c > 0 and c < 4294967295
        ip = []
        for i in xrange(3, 0, -1):
            p = 256 ** i
            ip.append(c/p)
            c -= (c/p)*p
        ip.append(c)
        return '.'.join([str(x) for x in ip])
    
    def dot2num(s):
        ip = [int(x) for x in s.split('.')]
        i = 0
        for x in xrange(3, 0, -1):
            i += ip.pop(0) * (256 ** x)
        i += ip.pop(0)
        return i
    
    Ip flame
    Posted by Jomas56 on Sun, 04/29/2007 - 07:04.
    What happened? fetish toons That fetish toons and cartoons. big boobs hardcore I see on her big boobs hardcore. asian teen sucking Asian teen sucking is very good. anal cream pies There are anal cream pies, isn't it? mature big dildos Mature big dildos are attractive. lesbian dildo movies Watch lesbian dildo movies on plasma. gay cock hard His gay cock hard moving into Jack. ass big wet His ass big wet and smooth. teens tricked Teens tricked are very interesting. cum pussy wet Her cum pussy wet is pretty. mature beauty ass Dan said: " mature beauty ass ." teens undressing There some teens undressing in the diner-room. lesbian double dildo What do you think about lesbian double dildo? big boobs in There are big boobs in her red dress. asian undressing See! That asian undressing! anal cum extreme Anna has anal cum extreme. It is weather.