[Checkins] SVN: z3c.iplocation/trunk/src/z3c/iplocation/ This
package implemented an IP locator utility,
which allows to look up the
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Mar 2 08:20:57 EST 2007
Log message for revision 72960:
This package implemented an IP locator utility, which allows to look up the
location for a given IP address. The interfaces and base implementation is
generic, but specific implementations are provided for the Ipligence
databases. I have included their demo sets, but have not tested against the
full database. However, the code is designed to be pretty efficient; I will
do some performance testing later.
Changed:
A z3c.iplocation/trunk/src/z3c/iplocation/
A z3c.iplocation/trunk/src/z3c/iplocation/README.txt
A z3c.iplocation/trunk/src/z3c/iplocation/__init__.py
A z3c.iplocation/trunk/src/z3c/iplocation/interfaces.py
A z3c.iplocation/trunk/src/z3c/iplocation/ipligence-basic-demo.txt
A z3c.iplocation/trunk/src/z3c/iplocation/ipligence-lite-demo.txt
A z3c.iplocation/trunk/src/z3c/iplocation/ipligence-max-demo.txt
A z3c.iplocation/trunk/src/z3c/iplocation/ipligence.py
A z3c.iplocation/trunk/src/z3c/iplocation/locator.py
A z3c.iplocation/trunk/src/z3c/iplocation/tests.py
-=-
Added: z3c.iplocation/trunk/src/z3c/iplocation/README.txt
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/README.txt 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/README.txt 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,249 @@
+==========
+IP Locator
+==========
+
+The IP Locator is a utility that provides a location for a particular IP
+address.
+
+ >>> from z3c.iplocation import locator
+ >>> loc = locator.IPLocator()
+
+A location can be retrieved using:
+
+ >>> loc.get('10.0.0.1')
+
+If no location was found, as it is the case here, the default value which is
+``None`` by default is returned. Of course, you can specify an alternative
+default value:
+
+ >>> loc.get('10.0.0.1', default=1)
+ 1
+
+If the passed in value is not a valid IP address, an error is raised:
+
+ >>> loc.get('10.0.0.x')
+ Traceback (most recent call last):
+ ...
+ ValueError: invalid literal for int(): x
+
+An extension to the ip locator API is the ip location management, which allows
+you to manage the locations within the utility. Let's now add a location.
+
+ >>> us = locator.Location('24.225.0.0', '24.225.255.255', u'United States')
+ >>> us
+ <Location 24.225.0.0-24.225.255.255 u'United States'>
+
+ >>> loc.add(us)
+
+We can now locate IPs within this range:
+
+ >>> loc.get('24.225.10.88')
+ <Location 24.225.0.0-24.225.255.255 u'United States'>
+
+Adding the same location again, is simply ignored:
+
+ >>> loc.add(us)
+
+Locations can as easily be removed:
+
+ >>> loc.remove(us)
+
+ >>> loc.get('24.225.10.88')
+
+Deleting a non-existent location is silently ignored:
+
+ >>> loc.remove(us)
+
+
+IPligence Locations
+-------------------
+
+One of the providers for IP to location mappings is IPligence at
+www.ipligence.com.
+
+
+Lite Database
+~~~~~~~~~~~~~
+
+Let's load their demo version of the lite database:
+
+ >>> import os
+ >>> file = open(os.path.join(dirpath, 'ipligence-lite-demo.txt'), 'r')
+
+ # Read some lines first
+ >>> for count in xrange(5):
+ ... print file.readline().strip()
+ ############ IPligence Lite DEMO FILE ###############
+ (c) IPligence. All rights reserved.
+ For more information visit http://www.ipligence.com
+ #####################################################
+ <BLANKLINE>
+
+Let's now generate the locator:
+
+ >>> from z3c.iplocation import ipligence
+ >>> liteLocator = ipligence.createLocator(file, ipligence.LiteLocation)
+
+We can now lookup locations:
+
+ >>> loc = liteLocator.get('24.225.10.88')
+ >>> loc
+ <LiteLocation 24.225.0.0-24.225.255.255 u'UNITED STATES'>
+
+ >>> loc.ipFrom
+ '24.225.0.0'
+ >>> loc.ipTo
+ '24.225.255.255'
+ >>> loc.name
+ u'UNITED STATES'
+
+ >>> loc.decimalFrom
+ 417398784
+ >>> loc.decimalTo
+ 417464319
+ >>> loc.countryCode
+ 'US'
+ >>> loc.countryName
+ 'UNITED STATES'
+ >>> loc.continentCode
+ 'NA'
+ >>> loc.continentName
+ 'NORTH AMERICA'
+
+
+Basic Database
+~~~~~~~~~~~~~~
+
+Let's load their demo version of the basic database:
+
+ >>> import os
+ >>> file = open(os.path.join(dirpath, 'ipligence-basic-demo.txt'), 'r')
+
+ # Read some lines first
+ >>> for count in xrange(5):
+ ... print file.readline().strip()
+ ############ IPligence Basic DEMO FILE ###############
+ (c) IPligence. All rights reserved.
+ For more information visit http://www.ipligence.com
+ #####################################################
+ <BLANKLINE>
+
+Let's now generate the locator:
+
+ >>> from z3c.iplocation import ipligence
+ >>> basicLocator = ipligence.createLocator(file, ipligence.BasicLocation)
+
+We can now lookup locations:
+
+ >>> loc = basicLocator.get('62.40.2.132')
+ >>> loc
+ <BasicLocation 62.40.2.40-62.40.2.255 u'GERMANY'>
+
+ >>> loc.decimalFrom
+ 1042809384
+ >>> loc.decimalTo
+ 1042809599
+ >>> loc.countryCode
+ 'DE'
+ >>> loc.countryName
+ 'GERMANY'
+ >>> loc.continentCode
+ 'EU'
+ >>> loc.continentName
+ 'EUROPE'
+ >>> loc.owner
+ 'KLOECKNER-MOELLER GMBH'
+ >>> loc.timeZone
+ 'GMT+1'
+ >>> loc.regionCode
+ 'HE'
+ >>> loc.regionName
+ 'HESSEN'
+
+
+Max Database
+~~~~~~~~~~~~
+
+Let's load their demo version of the max database:
+
+ >>> import os
+ >>> file = open(os.path.join(dirpath, 'ipligence-max-demo.txt'), 'r')
+
+ # Read some lines first
+ >>> for count in xrange(5):
+ ... print file.readline().strip()
+ ############ IPligence Max DEMO FILE ###############
+ (c) IPligence. All rights reserved.
+ For more information visit http://www.ipligence.com
+ #####################################################
+ <BLANKLINE>
+
+Let's now generate the locator:
+
+ >>> from z3c.iplocation import ipligence
+ >>> maxLocator = ipligence.createLocator(file, ipligence.MaxLocation)
+
+We can now lookup locations:
+
+ >>> loc = maxLocator.get('62.21.101.13')
+ >>> loc
+ <MaxLocation 62.21.100.0-62.21.102.255 u'POLAND'>
+
+ >>> loc.decimalFrom
+ 1041589248
+ >>> loc.decimalTo
+ 1041590015
+ >>> loc.countryCode
+ 'PL'
+ >>> loc.countryName
+ 'POLAND'
+ >>> loc.continentCode
+ 'EU'
+ >>> loc.continentName
+ 'EUROPE'
+ >>> loc.owner
+ 'INTERNET CABLE PROVIDER'
+ >>> loc.timeZone
+ 'GMT+1'
+ >>> loc.regionCode
+
+ >>> loc.regionName
+
+ >>> loc.cityName
+ 'WARSAW'
+ >>> loc.countyName
+
+ >>> loc.latitude
+ 52.25
+ >>> loc.longitude
+ 21.0
+
+
+Converting IPs to Decimals
+--------------------------
+
+In order to efficiently look up the location from the given IP, IPs are
+converted to decimals.
+
+ >>> from z3c.iplocation import locator
+
+ >>> locator.getDecimal('123.29.4.1')
+ 2065499137
+ >>> locator.getDecimal('0.0.0.0')
+ 0
+ >>> locator.getDecimal('255.255.255.255')
+ 4294967295L
+
+
+Converting Decimals to IPs
+--------------------------
+
+In order to provide a user-readable format of the IPs, the decimals can be
+converted back to IP addresses:
+
+ >>> locator.getIP(2065499137)
+ '123.29.4.1'
+ >>> locator.getIP(0)
+ '0.0.0.0'
+ >>> locator.getIP(4294967295L)
+ '255.255.255.255'
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.iplocation/trunk/src/z3c/iplocation/__init__.py
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/__init__.py 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/__init__.py 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1 @@
+# Make a package.
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.iplocation/trunk/src/z3c/iplocation/interfaces.py
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/interfaces.py 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/interfaces.py 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,155 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""IP Locator Interfaces
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import zope.interface
+import zope.schema
+from z3c.schema import ip
+
+class ILocation(zope.interface.Interface):
+ """A location for a given IP range."""
+
+ ipFrom = ip.IPAddress(
+ title=u'IP From',
+ description=u'First IP address in Netblock.',
+ required=True)
+
+ ipTo = ip.IPAddress(
+ title=u'IP To',
+ description=u'Last IP address in Netblock.',
+ required=True)
+
+ name = zope.schema.TextLine(
+ title=u'Name',
+ description=u'The name of the location of the IP range.',
+ required=True)
+
+
+class IIPligenceLiteLocation(ILocation):
+ """An IPligence compatible location for the lite version of the data."""
+
+ decimalFrom = zope.schema.Int(
+ title=u'Decimal IP From',
+ description=u'First IP address in Netblock as a decimal.',
+ required=True)
+
+ decimalTo = zope.schema.Int(
+ title=u'Decimal IP To',
+ description=u'Last IP address in Netblock as a decimal.',
+ required=True)
+
+ countryCode = zope.schema.ASCIILine(
+ title=u'Country Code',
+ description=u'Two characters country code based on ISO 3166.',
+ min_length=2,
+ max_length=2,
+ required=True)
+
+ countryName = zope.schema.ASCIILine(
+ title=u'Country Name',
+ description=u'Country name based on ISO 3166.',
+ required=True)
+
+ continentCode = zope.schema.ASCIILine(
+ title=u'Continent Code',
+ description=u'Two characters continent code based on ISO 3166.',
+ min_length=2,
+ max_length=2,
+ required=True)
+
+ continentName = zope.schema.ASCIILine(
+ title=u'Continent Name',
+ description=u'Continent name based on ISO 3166.',
+ required=True)
+
+
+class IIPligenceBasicLocation(IIPligenceLiteLocation):
+ """An IPligence compatible location for the basic version of the data."""
+
+ owner = zope.schema.ASCIILine(
+ title=u'Owner',
+ description=u'Company owner or Internet Service Provider.',
+ required=True)
+
+ timeZone = zope.schema.ASCIILine(
+ title=u'Time Zone',
+ description=u'Time Zone',
+ required=True)
+
+ regionCode = zope.schema.ASCIILine(
+ title=u'Region Code',
+ description=u'Two characters region or state code.',
+ min_length=2,
+ max_length=2,
+ required=False)
+
+ regionName = zope.schema.ASCIILine(
+ title=u'Region Name',
+ description=u'Region or State name.',
+ required=False)
+
+
+class IIPligenceMaxLocation(IIPligenceBasicLocation):
+ """An IPligence compatible location for the max version of the data."""
+
+ cityName = zope.schema.ASCIILine(
+ title=u'City Name',
+ description=u'City name.',
+ required=True)
+
+ countyName = zope.schema.ASCIILine(
+ title=u'County Name',
+ description=u'County name.',
+ required=False)
+
+ latitude = zope.schema.Float(
+ title=u'Latitude',
+ description=u'Latitude.',
+ required=True)
+
+ longitude = zope.schema.Float(
+ title=u'Longitude',
+ description=u'Longitude.',
+ required=True)
+
+
+class IIPLocator(zope.interface.Interface):
+ """Component to retrieve the location of an IP address."""
+
+ def get(ip, default=None):
+ """Return a location for the given IP.
+
+ The location must at least implement ``ILocation``, but might also
+ implement any of the extended location interfaces.
+
+ If no location was found, return the default value.
+ """
+
+class IIPLocatorManagement(zope.interface.Interface):
+ """Manage IP Locator data."""
+
+ def add(location):
+ """Add an IP location.
+
+ If the location is already in the locator, ignore the request.
+ """
+
+ def remove(location):
+ """Remove an IP location.
+
+ If the location is not in the locator, ignore the request.
+ """
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.iplocation/trunk/src/z3c/iplocation/ipligence-basic-demo.txt
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/ipligence-basic-demo.txt 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/ipligence-basic-demo.txt 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,46 @@
+############ IPligence Basic DEMO FILE ###############
+(c) IPligence. All rights reserved.
+For more information visit http://www.ipligence.com
+#####################################################
+
+"1042809088","1042809103","DE","GERMANY","EU","EUROPE","PIRONET NDH AG","GMT+1","HE","HESSEN"
+"1042809104","1042809343","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","HE","HESSEN"
+"1042809344","1042809351","DE","GERMANY","EU","EUROPE","KLOECKNER-MOELLER GMBH","GMT+1","HE","HESSEN"
+"1042809352","1042809359","DE","GERMANY","EU","EUROPE","ARNO GMBH","GMT+1","HE","HESSEN"
+"1042809360","1042809367","DE","GERMANY","EU","EUROPE","MAHA MASCHINENBAU","GMT+1","HE","HESSEN"
+"1042809368","1042809375","DE","GERMANY","EU","EUROPE","KLOECKNER-MOELLER GMBH","GMT+1","HE","HESSEN"
+"1042809376","1042809383","DE","GERMANY","EU","EUROPE","MAHA MASCHINENBAU","GMT+1","HE","HESSEN"
+"1042809384","1042809599","DE","GERMANY","EU","EUROPE","KLOECKNER-MOELLER GMBH","GMT+1","HE","HESSEN"
+"1042809600","1042809855","DE","GERMANY","EU","EUROPE","SUSPA SPANNBETON GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042809856","1042809863","DE","GERMANY","EU","EUROPE","E-PROMPT GERMANY COMMERCIAL SERVICES GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042809864","1042809871","DE","GERMANY","EU","EUROPE","INTERNATIONALER JUGENDAUSTAUSCH- UND BESUCHERDIENST DER BRD","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042809872","1042809887","DE","GERMANY","EU","EUROPE","VICOMS GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042809888","1042809919","DE","GERMANY","EU","EUROPE","KATH HOSPITALVEREINIGUNG MAERKISCHER KREIS GEM GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042809920","1042809983","DE","GERMANY","EU","EUROPE","MHP MANNESMANN PRAEZISROHR GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042809984","1042810047","DE","GERMANY","EU","EUROPE","H2O - IT-MEDIEN-MARKETING - EK","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042810048","1042810079","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042810080","1042810111","DE","GERMANY","EU","EUROPE","MOSKITOPROJEKT","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042810112","1042810119","DE","GERMANY","EU","EUROPE","TOP DIREKT GMBH KASSEL","GMT+1","HE","HESSEN"
+"1042810120","1042810127","DE","GERMANY","EU","EUROPE","RIGHT TIME GMBH LUENEBURG","GMT+1","NI","NIEDERSACHSEN"
+"1042810128","1042810143","DE","GERMANY","EU","EUROPE","INTETRA NETWORK GMBH","GMT+1","HE","HESSEN"
+"1042810144","1042810207","DE","GERMANY","EU","EUROPE","BRANION GMBH","GMT+1","HE","HESSEN"
+"1042810208","1042810239","DE","GERMANY","EU","EUROPE","AL HAMRA CAFE","GMT+1","HE","HESSEN"
+"1042810240","1042810303","DE","GERMANY","EU","EUROPE","PC-PROFI","GMT+1","HE","HESSEN"
+"1042810304","1042810311","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","HE","HESSEN"
+"1042810312","1042810319","DE","GERMANY","EU","EUROPE","ZAHRA NADERI","GMT+1","HE","HESSEN"
+"1042810320","1042810327","DE","GERMANY","EU","EUROPE","ACUCORP DEUTSCHLAND GMBH","GMT+1","HE","HESSEN"
+"1042810328","1042810623","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","HE","HESSEN"
+"1042810624","1042810655","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042810656","1042810687","DE","GERMANY","EU","EUROPE","LU SNACK FOODS GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042810688","1042810751","DE","GERMANY","EU","EUROPE","BUNDESVERSICHERUNGSAMT","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042810752","1042810815","DE","GERMANY","EU","EUROPE","PELIKAN GMBH HANNOVER","GMT+1","NI","NIEDERSACHSEN"
+"1042810816","1042810879","DE","GERMANY","EU","EUROPE","T-SYSTEMS INTERNATIONAL GMBH","GMT+1","BW","BADEN-WURTTEMBERG"
+"1042810880","1042811135","DE","GERMANY","EU","EUROPE","PIRONET NDH AG","GMT+1","HE","HESSEN"
+"1042811136","1042811151","DE","GERMANY","EU","EUROPE","LANDESVERMESSUNGSAMT NRW","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042811152","1042811159","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042811160","1042811167","DE","GERMANY","EU","EUROPE","PTC GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042811168","1042811175","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042811176","1042811183","DE","GERMANY","EU","EUROPE","GREY COMPUTER COLOGNE GMBH","GMT+1","NW","NORDRHEIN-WESTFALEN"
+"1042811184","1042811191","DE","GERMANY","EU","EUROPE","NDH IT SERVICE AG","GMT+1","HE","HESSEN"
+"1042811192","1042811199","DE","GERMANY","EU","EUROPE","S & T SYSTEMTECHNIK GMBH","GMT+1","HE","HESSEN"
+"1042811200","1042811263","DE","GERMANY","EU","EUROPE","INNOVATIONSFABRIK GMBH","GMT+1","HE","HESSEN"
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/ipligence-basic-demo.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.iplocation/trunk/src/z3c/iplocation/ipligence-lite-demo.txt
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/ipligence-lite-demo.txt 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/ipligence-lite-demo.txt 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,47 @@
+############ IPligence Lite DEMO FILE ###############
+(c) IPligence. All rights reserved.
+For more information visit http://www.ipligence.com
+#####################################################
+
+"0417366016","0417398783","CA","CANADA","NA","NORTH AMERICA"
+"0417398784","0417464319","US","UNITED STATES","NA","NORTH AMERICA"
+"0417464320","0417529855","CA","CANADA","NA","NORTH AMERICA"
+"0417529856","0417532671","US","UNITED STATES","NA","NORTH AMERICA"
+"0417532672","0417532927","GB","UNITED KINGDOM","EU","EUROPE"
+"0417532928","0417533439","US","UNITED STATES","NA","NORTH AMERICA"
+"0417533440","0417533503","GB","UNITED KINGDOM","EU","EUROPE"
+"0417533504","0417533599","US","UNITED STATES","NA","NORTH AMERICA"
+"0417533600","0417533631","GB","UNITED KINGDOM","EU","EUROPE"
+"0417533632","0417734655","US","UNITED STATES","NA","NORTH AMERICA"
+"0417734656","0417775615","US","UNITED STATES","NA","NORTH AMERICA"
+"0417775616","0417791999","US","UNITED STATES","NA","NORTH AMERICA"
+"0417792000","0417800191","CA","CANADA","NA","NORTH AMERICA"
+"0417800192","0417808383","BS","BAHAMAS","NA","NORTH AMERICA"
+"0417808384","0417816575","CA","CANADA","NA","NORTH AMERICA"
+"0417816576","0417857535","US","UNITED STATES","NA","NORTH AMERICA"
+"0417857536","0417923071","AR","ARGENTINA","SA","SOUTH AMERICA"
+"0417923072","0418062335","US","UNITED STATES","NA","NORTH AMERICA"
+"0418062336","0418066431","CA","CANADA","NA","NORTH AMERICA"
+"0418066432","0418078719","US","UNITED STATES","NA","NORTH AMERICA"
+"0418078720","0418119679","CA","CANADA","NA","NORTH AMERICA"
+"0418119680","0418643967","US","UNITED STATES","NA","NORTH AMERICA"
+"0418643968","0418668543","CA","CANADA","NA","NORTH AMERICA"
+"0418668544","0418676735","US","UNITED STATES","NA","NORTH AMERICA"
+"0418676736","0418687743","BS","BAHAMAS","NA","NORTH AMERICA"
+"0418687744","0418687999","DM","DOMINICA","NA","NORTH AMERICA"
+"0418688000","0418693119","BS","BAHAMAS","NA","NORTH AMERICA"
+"0418693120","0418709503","CA","CANADA","NA","NORTH AMERICA"
+"0418709504","0419430399","US","UNITED STATES","NA","NORTH AMERICA"
+"0419430400","0436207615","GB","UNITED KINGDOM","EU","EUROPE"
+"0436207616","0536870911","US","UNITED STATES","NA","NORTH AMERICA"
+"0536870912","0553648127","GB","UNITED KINGDOM","EU","EUROPE"
+"0553648128","0671088639","US","UNITED STATES","NA","NORTH AMERICA"
+"0671088640","0687865855","BR","BRAZIL","SA","SOUTH AMERICA"
+"0687865856","0700448767","MU","MAURITIUS","AF","AFRICA"
+"0700448768","0700579839","ZA","SOUTH AFRICA","AF","AFRICA"
+"0700579840","0703594495","MU","MAURITIUS","AF","AFRICA"
+"0703594496","0704118783","ZA","SOUTH AFRICA","AF","AFRICA"
+"0704118784","0704380927","MA","MOROCCO","AF","AFRICA"
+"0704380928","0704643071","MU","MAURITIUS","AF","AFRICA"
+"0704643072","0721420287","US","UNITED STATES","NA","NORTH AMERICA"
+"0721420288","0738197503","JP","JAPAN","AS","ASIA"
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/ipligence-lite-demo.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.iplocation/trunk/src/z3c/iplocation/ipligence-max-demo.txt
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/ipligence-max-demo.txt 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/ipligence-max-demo.txt 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,47 @@
+############ IPligence Max DEMO FILE ###############
+(c) IPligence. All rights reserved.
+For more information visit http://www.ipligence.com
+#####################################################
+
+"1041563382","1041563382","SE","SWEDEN","EU","EUROPE","TELIA AB","GMT+1","","","STOCKHOLM","","59.33","18.05"
+"1041563383","1041563387","SE","SWEDEN","EU","EUROPE","TELIA NETWORK SERVICES","GMT+1","","","STOCKHOLM","","59.33","18.05"
+"1041563388","1041563391","SE","SWEDEN","EU","EUROPE","TELIA AB","GMT+1","","","STOCKHOLM","","59.33","18.05"
+"1041563392","1041563635","SE","SWEDEN","EU","EUROPE","TELIA NETWORK SERVICES","GMT+1","","","STOCKHOLM","","59.33","18.05"
+"1041563636","1041563647","SE","SWEDEN","EU","EUROPE","TELIA AB","GMT+1","","","STOCKHOLM","","59.33","18.05"
+"1041563648","1041571583","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","WARSAW","","52.25","21"
+"1041571584","1041571588","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","POZNAN","","52.42","16.97"
+"1041571589","1041571589","PL","POLAND","EU","EUROPE","ASK CHABROWA","GMT+1","","","POZNAN","","52.42","16.97"
+"1041571590","1041571839","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","POZNAN","","52.42","16.97"
+"1041571840","1041588223","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","WARSAW","","52.25","21"
+"1041588224","1041589055","PL","POLAND","EU","EUROPE","ICPNET COLLOCATION AND SERVER'S FARM","GMT+1","","","WARSAW","","52.25","21"
+"1041589056","1041589087","PL","POLAND","EU","EUROPE","ICPNET COLLOCATIONAND SERVER'S FARM","GMT+1","","","POZNAN","","52.42","16.97"
+"1041589088","1041589247","PL","POLAND","EU","EUROPE","ICPNET COLLOCATION AND SERVER'S FARM","GMT+1","","","WARSAW","","52.25","21"
+"1041589248","1041590015","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","WARSAW","","52.25","21"
+"1041590016","1041590271","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","SREM","","52.08","17.02"
+"1041590272","1041592063","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","WARSAW","","52.25","21"
+"1041592064","1041592319","PL","POLAND","EU","EUROPE","ICP INTERNET CABLE PROVIDER","GMT+1","","","WARSAW","","52.25","21"
+"1041592320","1041596415","PL","POLAND","EU","EUROPE","INTERNET CABLE PROVIDER","GMT+1","","","WARSAW","","52.25","21"
+"1041596416","1041606911","NL","NETHERLANDS","EU","EUROPE","FREELER DIAL-IN POOL","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041606912","1041606975","NL","NETHERLANDS","EU","EUROPE","FREELER DATAPATH A","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041606976","1041607039","NL","NETHERLANDS","EU","EUROPE","ENERTEL NV","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041607040","1041607103","NL","NETHERLANDS","EU","EUROPE","FREELER DATAPATH B","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041607104","1041607167","NL","NETHERLANDS","EU","EUROPE","ENERTEL NV","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041607168","1041623039","NL","NETHERLANDS","EU","EUROPE","FREELER ADSL POOL","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041623040","1041625087","NL","NETHERLANDS","EU","EUROPE","PUBLISHNET NETWORK USED FOR DHCP DSL CONNECTIONS","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041625088","1041626111","NL","NETHERLANDS","EU","EUROPE","NET IN NET DIAL-IN AND HOSTING","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041626112","1041626367","NL","NETHERLANDS","EU","EUROPE","HILBRINK IT SOLUTIONS","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041626368","1041626623","NL","NETHERLANDS","EU","EUROPE","ENERTEL NV","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041626624","1041627135","NL","NETHERLANDS","EU","EUROPE","NETWORK USED FOR BUSINESS DSL CONNECTIONS","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041627136","1041628671","NL","NETHERLANDS","EU","EUROPE","ENERTEL NV CONSUMER CONNECT PRODUCT","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041628672","1041629183","NL","NETHERLANDS","EU","EUROPE","FREELER ADSL POOL","GMT+1","","","AMSTERDAM","","52.35","4.92"
+"1041629184","1041631231","ES","SPAIN","EU","EUROPE","UUNET SPAIN INFRASTRUCTURE","GMT+1","","","MADRID","","40.4","-3.68"
+"1041631232","1041631263","ES","SPAIN","EU","EUROPE","TEK TRANSLATION INTERNATIONAL SA","GMT+1","","","MADRID","","40.4","-3.68"
+"1041631264","1041631279","ES","SPAIN","EU","EUROPE","WHOLESALER COMPANY","GMT+1","","","BARCELONA","","41.38","2.18"
+"1041631280","1041631295","ES","SPAIN","EU","EUROPE","ZENITH MEDIA / GRUPO DELVICO RED CELL SA","GMT+1","","","MADRID","","40.4","-3.68"
+"1041631296","1041631359","ES","SPAIN","EU","EUROPE","UUNET TECHNOLOGIES INC","GMT+1","","","MADRID","","40.4","-3.68"
+"1041631360","1041631375","ES","SPAIN","EU","EUROPE","AFFILIATED COMPUTER SERVICES -","GMT+1","","","BARCELONA","","41.38","2.18"
+"1041631376","1041631391","ES","SPAIN","EU","EUROPE","UUNET TECHNOLOGIES INC","GMT+1","","","BARCELONA","","41.38","2.18"
+"1041631392","1041631407","ES","SPAIN","EU","EUROPE","FAGOR ELECTRONICA SCOOP","GMT+1","","","MONDRAGON","","43.07","-2.48"
+"1041631408","1041631423","ES","SPAIN","EU","EUROPE","UUNET TECHNOLOGIES INC","GMT+1","","","MONDRAGON","","43.07","-2.48"
+"1041631424","1041631439","ES","SPAIN","EU","EUROPE","UUNET TECHNOLOGIES INC","GMT+1","","","BARCELONA","","41.38","2.18"
+"1041631440","1041631447","ES","SPAIN","EU","EUROPE","OOCL","GMT+1","","","BARCELONA","","41.38","2.18"
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/ipligence-max-demo.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.iplocation/trunk/src/z3c/iplocation/ipligence.py
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/ipligence.py 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/ipligence.py 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,117 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""IP Locator for IPligence Data
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import csv
+import zope.interface
+from zope.schema.fieldproperty import FieldProperty
+
+from z3c.iplocation import interfaces, locator
+
+class LiteLocation(locator.Location):
+ zope.interface.implements(interfaces.IIPligenceLiteLocation)
+
+ decimalFrom = FieldProperty(
+ interfaces.IIPligenceLiteLocation['decimalFrom'])
+ decimalTo = FieldProperty(
+ interfaces.IIPligenceLiteLocation['decimalTo'])
+ countryCode = FieldProperty(
+ interfaces.IIPligenceLiteLocation['countryCode'])
+ countryName = FieldProperty(
+ interfaces.IIPligenceLiteLocation['countryName'])
+ continentCode = FieldProperty(
+ interfaces.IIPligenceLiteLocation['continentCode'])
+ continentName = FieldProperty(
+ interfaces.IIPligenceLiteLocation['continentName'])
+
+ def __init__(self, decimalFrom, decimalTo, countryCode, countryName,
+ continentCode, continentName):
+ self.decimalFrom = int(decimalFrom)
+ self.decimalTo = int(decimalTo)
+ self.countryCode = countryCode
+ self.countryName = countryName
+ self.continentCode = continentCode
+ self.continentName = continentName
+
+ @property
+ def ipFrom(self):
+ return locator.getIP(self.decimalFrom)
+
+ @property
+ def ipTo(self):
+ return locator.getIP(self.decimalTo)
+
+ @property
+ def name(self):
+ return unicode(self.countryName)
+
+
+class BasicLocation(LiteLocation):
+ zope.interface.implements(interfaces.IIPligenceBasicLocation)
+
+ owner = FieldProperty(
+ interfaces.IIPligenceBasicLocation['owner'])
+ timeZone = FieldProperty(
+ interfaces.IIPligenceBasicLocation['timeZone'])
+ regionCode = FieldProperty(
+ interfaces.IIPligenceBasicLocation['regionCode'])
+ regionName = FieldProperty(
+ interfaces.IIPligenceBasicLocation['regionName'])
+
+ def __init__(self, decimalFrom, decimalTo, countryCode, countryName,
+ continentCode, continentName, owner, timeZone,
+ regionCode, regionName):
+ super(BasicLocation, self).__init__(
+ decimalFrom, decimalTo, countryCode, countryName,
+ continentCode, continentName)
+ self.owner = owner
+ self.timeZone = timeZone
+ self.regionCode = regionCode or None
+ self.regionName = regionName or None
+
+
+class MaxLocation(BasicLocation):
+ zope.interface.implements(interfaces.IIPligenceMaxLocation)
+
+ cityName = FieldProperty(
+ interfaces.IIPligenceMaxLocation['cityName'])
+ countryName = FieldProperty(
+ interfaces.IIPligenceMaxLocation['countryName'])
+ latitude = FieldProperty(
+ interfaces.IIPligenceMaxLocation['latitude'])
+ longitude = FieldProperty(
+ interfaces.IIPligenceMaxLocation['longitude'])
+
+ def __init__(self, decimalFrom, decimalTo, countryCode, countryName,
+ continentCode, continentName, owner, timeZone,
+ regionCode, regionName, cityName, countyName,
+ latitude, longitude):
+ super(MaxLocation, self).__init__(
+ decimalFrom, decimalTo, countryCode, countryName, continentCode,
+ continentName, owner, timeZone, regionCode, regionName)
+ self.cityName = cityName
+ self.countyName = countyName or None
+ self.latitude = float(latitude)
+ self.longitude = float(longitude)
+
+
+def createLocator(file, klass=LiteLocation):
+ liteLocator = locator.IPLocator()
+ for row in csv.reader(file):
+ loc = klass(*row)
+ liteLocator.add(loc, loc.decimalFrom, loc.decimalTo)
+ return liteLocator
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/ipligence.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.iplocation/trunk/src/z3c/iplocation/locator.py
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/locator.py 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/locator.py 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,107 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""IP Locator Implementation.
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import persistent
+import zope.app.intid
+import zope.interface
+from BTrees import IOBTree, IFBTree, OIBTree
+from zc.catalog import index
+from zope.app.container import contained
+from zope.schema.fieldproperty import FieldProperty
+
+from z3c.iplocation import interfaces
+
+
+def getIP(decimal):
+ pieces = []
+ for pos in xrange(4):
+ piece = decimal/(256**(3-pos))
+ pieces.append(str(piece))
+ decimal -= piece*256**(3-pos)
+ return '.'.join(pieces)
+
+
+def getDecimal(ip):
+ return sum(
+ [int(piece)*(256**(3-pos))
+ for pos, piece in enumerate(ip.split('.'))])
+
+
+class Location(persistent.Persistent):
+ zope.interface.implements(interfaces.ILocation)
+
+ ipFrom = FieldProperty(interfaces.ILocation['ipFrom'])
+ ipTo = FieldProperty(interfaces.ILocation['ipTo'])
+ name = FieldProperty(interfaces.ILocation['name'])
+
+ def __init__(self, ipFrom, ipTo, name):
+ self.ipFrom = ipFrom
+ self.ipTo = ipTo
+ self.name = name
+
+ def __repr__(self):
+ return '<%s %s-%s %r>' %(
+ self.__class__.__name__, self.ipFrom, self.ipTo, self.name)
+
+
+class IPLocator(contained.Contained, persistent.Persistent):
+ """A persistent IP Locator implementation."""
+ zope.interface.implements(
+ interfaces.IIPLocator, interfaces.IIPLocatorManagement)
+
+ def __init__(self):
+ super(IPLocator, self).__init__()
+ self._locations = OIBTree.OITreeSet()
+ self._ids = zope.app.intid.IntIds()
+ self._ipFrom = index.ValueIndex()
+ self._ipTo = index.ValueIndex()
+
+ def get(self, ip, default=None):
+ """See interfaces.IIPLocator"""
+ ip = getDecimal(ip)
+ fromResult = self._ipFrom.apply(
+ {'between': (None, ip, False, False)})
+ toResult = self._ipTo.apply(
+ {'between': (ip, None, False, False)})
+ result = IFBTree.intersection(fromResult, toResult)
+ if not result:
+ return default
+ return self._ids.getObject(result[0])
+
+ def add(self, location, fromDecimal=None, toDecimal=None):
+ """See interfaces.IIPLocatorManagement
+
+ The ``fromDecimal`` and ``toDecimal`` optional arguments are designed
+ to save the conversion, if the IPs already exist in decimal format.
+ """
+ if location in self._locations.keys():
+ return
+ self._locations.insert(location)
+ uid = self._ids.register(location)
+ self._ipFrom.index_doc(uid, fromDecimal or getDecimal(location.ipFrom))
+ self._ipTo.index_doc(uid, toDecimal or getDecimal(location.ipTo))
+
+ def remove(self, location):
+ """See interfaces.IIPLocatorManagement"""
+ if location not in self._locations:
+ return
+ uid = self._ids.getId(location)
+ self._ipFrom.unindex_doc(uid)
+ self._ipTo.unindex_doc(uid)
+ self._ids.unregister(location)
+ self._locations.remove(location)
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/locator.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.iplocation/trunk/src/z3c/iplocation/tests.py
===================================================================
--- z3c.iplocation/trunk/src/z3c/iplocation/tests.py 2007-03-02 13:20:52 UTC (rev 72959)
+++ z3c.iplocation/trunk/src/z3c/iplocation/tests.py 2007-03-02 13:20:56 UTC (rev 72960)
@@ -0,0 +1,43 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tag test setup
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import doctest
+import os
+import unittest
+import zope.component
+from zope.testing.doctestunit import DocFileSuite
+from zope.app.keyreference import testing
+from zope.app.testing import placelesssetup
+
+dirpath = os.path.dirname(__file__)
+
+def setUp(test):
+ placelesssetup.setUp(test)
+ zope.component.provideAdapter(testing.SimpleKeyReference)
+
+def test_suite():
+ return unittest.TestSuite((
+ DocFileSuite(
+ 'README.txt',
+ globs={'dirpath': dirpath},
+ setUp=setUp, tearDown=placelesssetup.tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: z3c.iplocation/trunk/src/z3c/iplocation/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list