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

I would like to trace the origin of an IP to the country in Perl, is this possible? e.g.

x.x.x.x -> United States

Would this be possible in a currently available module? Or is there a way to check an online database of IP ranges?

Any advise would be greatly appreciated

Replies are listed 'Best First'.
Re: IP Origination
by Callum (Chaplain) on Jan 31, 2003 at 16:22 UTC
    This isn't advisable at all, the mapping simply isn't reliable.

    However, if you're determined then you may wish to look at Geo::IP

Re: IP Origination (find good IP net block maps)
by grinder (Bishop) on Jan 31, 2003 at 17:22 UTC

    If you are brave and insist on this approach, you will need to download an exhaustive list of country IP net blocks.

    Using a reputable search engine to look for ip net blocks by country will return a pile of pages that will contain something usable. For instance, Taiwan (useful to know if you want to block spam) has more than 56000 net blocks. Many of these are of course contiguous, so you would have to process them to coalesce neighboring blocks.

    See http://www.idefense.com/Intell/CI022702.html for an example. Unfortunately their data are stored in Excel files, but I'm sure if you look you'll be able to find someone who has zipped text on offer.

    A sample from the above source gives something like this:

    202.129.193.0 - 202.129.193.31 (CHEI-BING) Chei-Bing Co. Ltd.; i +nternet play game station; No3-9,Whaih-Ted st.,Pei-Toa,Taipei,TW,ROC; + TW 202.129.193.128 - 202.129.193.191 (DREAM-ISLAND) Dream island IN +TERNET COMPANY; Internet Play Game Station; No.419.WenHung Rd,.Taipei + Taiwan.R.O.C; TW 202.129.193.192 - 202.129.193.255 (KUEN-JIING) E-Cuntury Enterpr +ise Network Life House; Computer Sales and Game Zone Service Provider + and Coffee Shope; 1F, No.131-20 ,Sec.2,Keelung Rd.,Taipei; Taiwan,R. +O.C.; TW 202.129.193.32 - 202.129.193.63 (MAINLAND) MAINLAND Computer Com +pany; Internet Play Game Stateion Service; 1F,No60,Bai 3 Rd. street,K +eelung,Taiwan,R.O.C; TW 202.129.193.64 - 202.129.193.127 (GAME-HOUSE) Game-House interne +t information service and coffee shop; internet play game station; Su +ite B1,No.261,sec.2,Jincheng RD.,Tucheng City,Taipei,; Taiwan,R.O.C.; + TW 202.129.194.0 - 202.129.194.127 (INTERNET-PIONEER) INTERNET-PION +EER Co. Ltd.; Internet Play Game Stateion Service; 1F,No86-88,Sec 2,S +hpai Rd.,Taipei; Taiwan,R.O.C.; TW

    Note that the above information is current as of February 2002, i.e., nearly one year out of date. It would be a non-trivial task to keep this up to date.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
Re: IP Origination
by Marza (Vicar) on Jan 31, 2003 at 16:29 UTC

    What is it you are trying to accomplish?

    It is not that simple as to pick where the IP lives.

    Consider a multinational ISP(say Worldcom) where they have IP ranges that can span countries.

    Considier NAT. You may trace an IP range to say the US but the person you are tracking maybe in Germany.

    There are other examples, but what I need to understand is what you are trying to accomplish.

Re: IP Origination
by tomhukins (Curate) on Jan 31, 2003 at 17:58 UTC
    Searching Perl Monks for IP country or IP geograph returns useful information in less time than it takes to post a question.