Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

IP - country

by tune (Curate)
on Mar 01, 2001 at 23:10 UTC ( #61623=perlquestion: print w/replies, xml ) Need Help??

tune has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I am trying to create a utility that is finding out the client's country from its IP address.
Currently i try it with opening sockets to whois servers, and analyzing the responses. Sometimes it needs more query.

I wonder if it is any already invented module, or code that should help me find a more reliable solution, thank you.

-- tune

Replies are listed 'Best First'.
Re: IP - country
by merlyn (Sage) on Mar 01, 2001 at 23:12 UTC
    It's an impossible task. At best you could get a near guess, and you're probably already there. A whois query to will tell you 90% of what you need, but will be wrong 5% to 10% of the time.

    Why do you need this? You can't use it for legal reasons (since you can't be precisely accurate). Are you just curious about hits?

    -- Randal L. Schwartz, Perl hacker

      No i am not just curious. The policy of my employer is: block people of countries from signing up to our member areas, if there are too many hackers...
      I hope you see the point. The 5-10% is acceptable for them, and they know it is not completely accurate.
      I know it is not very ethic, but my job is just to create code... :)

      -- tune

        I don't get it. Your boss imagines that certain countries contain more hackers than others? What is this based on? Anyway, since you're the programmer, you should do your best to make the system impenetrable and give him assurances of this. Wasting your time on tracing IPs is not worth your time since the good hackers
        1. Don't come in bushels.
        2. Mask the real source of the attack.
        Frankly, I can't see what you hope to accomplish.
        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

        I see a little problem there: It seems to me that - probably having the biggest density of internet users per capita - the US would also have the largest number of hackers. Would you then have to block that country too?

        (Nota Bene: I have no statistics to back this. Just a guess)

        Brother Ade
Re: IP - country
by ncw (Friar) on Mar 02, 2001 at 04:02 UTC
    I've wanted to do the same thing in the past to ban troublesome countries from doing credit card transactions. Some countries like Russia have many people trying to abuse credit cards and no way legal recourse for people outside Russia.

    I've done this by hand using whois lookups to, and which cover everyone. This is time consuming in the extreme though!

    Recently I discovered which is a complete whois lookup on all possible ip addresses. I was contemplating downloading the info on the site, parsing it to produce a perl module which you could give an IP address to and it would return a country. This would be instant too!

      That is extremely insecure. I understand how this may give you a sense of security, but logging into your website from Russia via SpaceProxy completely defeats the purpose of this check. In effect, it is faster to bypass the check than it takes to actually perform the check! It is very dangerous to rely heavily on such services.
      AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
        I agree with you that this check isn't fool/hacker proof. However it is useful as an additional check. Believe me I've been there and had to deal with the chargebacks ;-)

        If you are talking about credit card transactions (which I was) then you are talking about secure transactions via https which in general aren't proxied.

        Of course most anyone technical can hide their true IP address but in our case that wasn't the sort of person we were dealing with.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://61623]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-05-21 00:22 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.