Map IP Address to a Geographical Location

  • http://www.dyndnsservices.com/knowshow.aspx?ID=4 has both the bulk insert procedure and needed format files for the geocity csv, per gratis.

    Thank you maxmind!!!

  • Link to format files for the maxmind geocity csv

    http://www.dyndnsservices.com/Format-files.zip

  • Geocity light is intentionally left wanting. Purchase the DB for more accurate results!

  • ozkary (7/10/2009)


    Comments posted to this topic are about the item <A HREF="/articles/SQL+Server/67215/">Map IP Address to a Geographical Location</A>

    hi friend

    you can get the location details of a particular ip address using this site

    http://www.ip-details.com

    they provide information about a particular ip address.

  • DECLARE@IPvalue BIGINT = 3222211197,

    @IPstring VARCHAR(15) = '192.15.10.125'

    -- SwePeso (value to string)

    SELECTCAST(CAST(SUBSTRING(Data, 1, 1) AS TINYINT) AS VARCHAR(3))

    + '.' + CAST(CAST(SUBSTRING(Data, 2, 1) AS TINYINT) AS VARCHAR(3))

    + '.' + CAST(CAST(SUBSTRING(Data, 3, 1) AS TINYINT) AS VARCHAR(3))

    + '.' + CAST(CAST(SUBSTRING(Data, 4, 1) AS TINYINT) AS VARCHAR(3)) AS IP

    FROM(

    VALUES(CAST(@IPvalue AS BINARY(4)))

    ) AS d(Data)

    -- SwePeso (string to value)

    SELECTCAST(16777216E * PARSENAME(@IPstring, 4)

    + 65536E * PARSENAME(@IPstring, 3)

    + 256E * PARSENAME(@IPstring, 2)

    + 1E * PARSENAME(@IPstring, 1) AS BIGINT) AS IP


    N 56°04'39.16"
    E 12°55'05.25"

  • Jeff Moden (4/18/2010)


    I'm asking because I'd really like to quit.

    And, you're correct. I quit twice for a year each and once for 3 months and not sure why I went back to it other than I like it and just wanted "one". The old saying holds true... "You're a puff away from a pack a day."

    It took me about a dozen tries to quit. Here is what worked for me:

    First and foremost, I cut out caffeine. Think about it, a nicotine fit looks just like being over-caffeinated.

    Second, after the taper down phase, on my quit date, I intentionally changed my self image to a non-smoker. Post signs on the bathroom mirror, the refrigerator, in your car, in your cubicle, etc. As you go to sleep at night create a mental image of yourself as a non-smoker. Maybe on a tropical beach, maybe wearing white at a party with beautiful women all wearing white, whatever works for you.

    Then when I felt a craving for a cigarette I would laugh at myself "don't be silly, you are a non-smoker." Nicotine is like the alien being in “Day of the Dove” http://en.wikipedia.org/wiki/Day_of_the_Dove feeding on your negative emotions. Laughing at it drives it away, stressing over it feeds it.

    Good luck. As others have said you are a very special person and a major resource to many of us. It would be a shame to lose you before your time.

    ===============================

    Anyway, back to the topic, I am trying to remember if anyone tested PARSENAME vs using a Tally Table. In this instance the tally table would only need to be 15 rows.

  • PARSENAME is a rEaLLy great tool here. Here's another way that isn't nearly as esthetically pleasing but is probably faster, just because it doesn't parse the string four times. In CLR form it would cook...

    create function dbo.ConvertIp2NumC(@ipAddr nvarchar(15))

    returns bigint

    as

    begin

    declare @ipPos int, @ipLen int, @ipChar nchar(1), @segNum int, @ipNum bigint

    set @segNum = 0

    set @ipPos = 1

    set @ipNum = 0

    set @ipLen = len(isnull(@ipAddr, ''))

    while @ipPos <= @ipLen begin

    set @ipChar = substring(@ipAddr, @ipPos, 1)

    if @ipChar = '.' begin

    set @ipNum = (256 * @ipNum) + cast(@segNum as bigint)

    set @segNum = 0

    end else

    set @segNum = (10 * @segNum) + cast(@ipChar as int)

    set @ipPos = @ipPos + 1

    end

    set @ipNum = (256 * @ipNum) + cast(@segNum as bigint)

    return @ipNum

    end

  • Nice article.

    Regards,

    Basit A. Farooq (MSC Computing, MCITP SQL Server 2005 & 2008, MCDBA SQL Server 2000)

    http://basitaalishan.com

Viewing 8 posts - 46 through 52 (of 52 total)

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