<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Python_-_Sqlite</id>
	<title>Python - Sqlite - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Python_-_Sqlite"/>
	<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Python_-_Sqlite&amp;action=history"/>
	<updated>2026-05-18T20:45:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Python_-_Sqlite&amp;diff=799&amp;oldid=prev</id>
		<title>PeterHarding at 02:03, 25 January 2008</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Python_-_Sqlite&amp;diff=799&amp;oldid=prev"/>
		<updated>2008-01-25T02:03:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:03, 25 January 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l331&quot;&gt;Line 331:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 331:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Python]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Python]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Database]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Python_-_Sqlite&amp;diff=792&amp;oldid=prev</id>
		<title>PeterHarding at 01:56, 25 January 2008</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Python_-_Sqlite&amp;diff=792&amp;oldid=prev"/>
		<updated>2008-01-25T01:56:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:56, 25 January 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l46&quot;&gt;Line 46:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 46:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=&lt;/del&gt;===Instructions&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=&lt;/del&gt;===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Instructions===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;GeoIP Country CSV Text Files&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;====&lt;/ins&gt;GeoIP Country CSV Text Files&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;MaxMind GeoIP databases are available in a Comma Separated Value (CSV) format, in addition to the binary format. These CSV files generally contain IP Address range and geographical data for all publicly assigned IPv4 addresses.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;MaxMind GeoIP databases are available in a Comma Separated Value (CSV) format, in addition to the binary format. These CSV files generally contain IP Address range and geographical data for all publicly assigned IPv4 addresses.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l116&quot;&gt;Line 116:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 116:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is useful to have the IP Number if you are performing IP Address lookups using a database. For example the following queries will find the country based on IP Address 24.24.24.24:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is useful to have the IP Number if you are performing IP Address lookups using a database. For example the following queries will find the country based on IP Address 24.24.24.24:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=&lt;/del&gt;===SQL Query&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=&lt;/del&gt;===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===SQL Query===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Python_-_Sqlite&amp;diff=791&amp;oldid=prev</id>
		<title>PeterHarding: New page: =References=  * http://www.hwaci.com/sw/sqlite/ * http://en.wikipedia.org/wiki/SQLite * http://www.sqlite.org/cvstrac/wiki * http://snippets.dzone.com/posts/show/653 * http://del.icio.us/p...</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Python_-_Sqlite&amp;diff=791&amp;oldid=prev"/>
		<updated>2008-01-25T01:54:53Z</updated>

		<summary type="html">&lt;p&gt;New page: =References=  * http://www.hwaci.com/sw/sqlite/ * http://en.wikipedia.org/wiki/SQLite * http://www.sqlite.org/cvstrac/wiki * http://snippets.dzone.com/posts/show/653 * http://del.icio.us/p...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=References=&lt;br /&gt;
&lt;br /&gt;
* http://www.hwaci.com/sw/sqlite/&lt;br /&gt;
* http://en.wikipedia.org/wiki/SQLite&lt;br /&gt;
* http://www.sqlite.org/cvstrac/wiki&lt;br /&gt;
* http://snippets.dzone.com/posts/show/653&lt;br /&gt;
* http://del.icio.us/pauldwaite/sqlite&lt;br /&gt;
&lt;br /&gt;
=Examples=&lt;br /&gt;
&lt;br /&gt;
* http://www.mail-archive.com/sqlite-users@sqlite.org/msg28608.html&lt;br /&gt;
* http://www.freenetpages.co.uk/hp/alan.gauld/tutdbms.htm&lt;br /&gt;
&lt;br /&gt;
==GeoLite==&lt;br /&gt;
&lt;br /&gt;
===Tables===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE locations(&lt;br /&gt;
                locid    INTEGER PRIMARY KEY,&lt;br /&gt;
                country TEXT,&lt;br /&gt;
                region    TEXT,&lt;br /&gt;
                city    TEXT,&lt;br /&gt;
                postalCode TEXT,&lt;br /&gt;
                latitude REAL,&lt;br /&gt;
                longitude REAL,&lt;br /&gt;
                dmaCode INTEGER,&lt;br /&gt;
                areaCode INTEGER)&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE blocks(&lt;br /&gt;
                startIpNum INTEGER,&lt;br /&gt;
                endIpNum INTEGER,&lt;br /&gt;
                locId INTEGER)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Data===&lt;br /&gt;
&lt;br /&gt;
* http://www.maxmind.com/app/geolitecity&lt;br /&gt;
* http://www.maxmind.com/app/csv&lt;br /&gt;
* http://www.maxmind.com/app/api&lt;br /&gt;
* http://www.maxmind.com/app/python&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Blocks table has 2,776,436 rows&lt;br /&gt;
Locations table has 159,488 rows&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Instructions====&lt;br /&gt;
&lt;br /&gt;
GeoIP Country CSV Text Files&lt;br /&gt;
&lt;br /&gt;
MaxMind GeoIP databases are available in a Comma Separated Value (CSV) format, in addition to the binary format. These CSV files generally contain IP Address range and geographical data for all publicly assigned IPv4 addresses.&lt;br /&gt;
&lt;br /&gt;
Due to the large size of geolocation databases, we generally recommend using our binary format with one of our APIs, since they are highly optimized for speed and disk space. On the other hand, if you have a requirement to import the data into a SQL database, the CSV format is recommended. We have listed some guidelines for importing and querying the data with a SQL database.&lt;br /&gt;
&lt;br /&gt;
====CSV Format====&lt;br /&gt;
&lt;br /&gt;
The CSV File contains six fields:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    * Beginning IP Address&lt;br /&gt;
    * Ending IP Address&lt;br /&gt;
    * Beginning IP Number*&lt;br /&gt;
    * Ending IP Number*&lt;br /&gt;
    * ISO 3166 Country Code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is an sample of how the CSV file is structured:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;begin_ip&amp;quot;,&amp;quot;end_ip&amp;quot;,&amp;quot;begin_num&amp;quot;,&amp;quot;end_num&amp;quot;,&amp;quot;country&amp;quot;,&amp;quot;name&amp;quot;&lt;br /&gt;
&amp;quot;61.88.0.0&amp;quot;,&amp;quot;61.91.255.255&amp;quot;,&amp;quot;1029177344&amp;quot;,&amp;quot;1029439487&amp;quot;,&amp;quot;AU&amp;quot;,&amp;quot;Australia&amp;quot;&lt;br /&gt;
&amp;quot;61.92.0.0&amp;quot;,&amp;quot;61.93.255.255&amp;quot;,&amp;quot;1029439488&amp;quot;,&amp;quot;1029570559&amp;quot;,&amp;quot;HK&amp;quot;,&amp;quot;Hong Kong&amp;quot;&lt;br /&gt;
&amp;quot;61.94.0.0&amp;quot;,&amp;quot;61.94.7.255&amp;quot;,&amp;quot;1029570560&amp;quot;,&amp;quot;1029572607&amp;quot;,&amp;quot;ID&amp;quot;,&amp;quot;Indonesia&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beginning IP Number and Ending IP Number are calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ipnum = 16777216*w + 65536*x + 256*y + z   (1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IP Address = w.x.y.z&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reverse of this formula is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
w = int ( ipnum / 16777216 ) % 256;&lt;br /&gt;
x = int ( ipnum / 65536    ) % 256;&lt;br /&gt;
y = int ( ipnum / 256      ) % 256;&lt;br /&gt;
z = int ( ipnum            ) % 256;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where % is the mod operator.&lt;br /&gt;
&lt;br /&gt;
Here is sample Perl code to convert the IP number to a IP address:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub numToStr {&lt;br /&gt;
  my ($ipnum) = @_;&lt;br /&gt;
  my $z = $ipnum % 256;&lt;br /&gt;
  $ipnum &amp;gt;&amp;gt;= 8;&lt;br /&gt;
  my $y = $ipnum % 256;&lt;br /&gt;
  $ipnum &amp;gt;&amp;gt;= 8;&lt;br /&gt;
  my $x = $ipnum % 256;&lt;br /&gt;
  $ipnum &amp;gt;&amp;gt;= 8;&lt;br /&gt;
  my $w = $ipnum % 256;&lt;br /&gt;
  return &amp;quot;$w.$x.$y.$z&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is useful to have the IP Number if you are performing IP Address lookups using a database. For example the following queries will find the country based on IP Address 24.24.24.24:&lt;br /&gt;
&lt;br /&gt;
====SQL Query====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT ip_country FROM geoip WHERE 404232216 BETWEEN begin_ip_num AND end_ip_num&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====MySQL Query====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT ip_country FROM geoip WHERE 404232216 &amp;gt;= begin_ip_num AND&lt;br /&gt;
	404232216 &amp;lt;= end_ip_num&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we used the formula (1) to compute the IP Number based on 24.24.24.24&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
404232216 = 16777216*24 + 65536*24 + 256*24 + 24&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides For more information on importing GeoIP CSV files into MySQL, see HOW-TO Import the MaxMind GeoIP Free Country CSV file into MySQL and save diskspace.&lt;br /&gt;
&lt;br /&gt;
For more information on importing GeoIP CSV files into Oracle 8i\+ with PL/SQL and SQL*Loader files included, see GeoIP01.zip on Sascha Pfalz&amp;#039;s download page.&lt;br /&gt;
&lt;br /&gt;
For more information on importing GeoIP CSV files into MS Access, see How to install the MaxMind GeoIP CSV databases into an MS Access Database.&lt;br /&gt;
&lt;br /&gt;
===Script===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;geolite&lt;br /&gt;
GeoLite City is a free IP to city database provided by MaxMind.&lt;br /&gt;
They provide a C API (and a python wrapper) for the database.&lt;br /&gt;
If you can&amp;#039;t compile the C sources on your server (or get a binary&lt;br /&gt;
version), this script might be helpful for you.&lt;br /&gt;
The script puts the geoip data in a sqllite database, and provides&lt;br /&gt;
interfaces for updating and searching the database.&lt;br /&gt;
&lt;br /&gt;
To use this script, get the database in CSV format:&lt;br /&gt;
http://www.maxmind.com/app/geolitecity&lt;br /&gt;
&lt;br /&gt;
You also need to have python 2.5 for this script (sqlite3 is used)&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
import sqlite3 as sqlite&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
def dottedQuadToNum(ip):&lt;br /&gt;
    &amp;quot;convert decimal dotted quad string to long integer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    hexn = &amp;#039;&amp;#039;.join([&amp;quot;%02X&amp;quot; % long(i) for i in ip.split(&amp;#039;.&amp;#039;)])&lt;br /&gt;
    return long(hexn, 16)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def cursorToDict(cursor):&lt;br /&gt;
    val = cursor.next()&lt;br /&gt;
    return dict([(cursor.description[i][0],val[i]) for i in xrange(len(cursor.description))])&lt;br /&gt;
&lt;br /&gt;
def test():&lt;br /&gt;
    import sqlite3&lt;br /&gt;
    from time import clock&lt;br /&gt;
    x = sqlite3.connect(&amp;#039;geolite.db&amp;#039;)&lt;br /&gt;
    y = x.cursor()&lt;br /&gt;
    ip = dottedQuadToNum(&amp;quot;84.108.189.94&amp;quot;)&lt;br /&gt;
    res = y.execute(&amp;#039;select * from blocks,locations where locations.locid = blocks.locid AND ? &amp;gt;= blocks.startIpNum AND ? &amp;lt;= blocks.endIpNum&amp;#039;, [ip,ip])&lt;br /&gt;
    begin = clock()&lt;br /&gt;
    f = res.next()&lt;br /&gt;
    end = clock()&lt;br /&gt;
    y.close()&lt;br /&gt;
    x.close()&lt;br /&gt;
    return end-begin, f&lt;br /&gt;
&lt;br /&gt;
def test2():&lt;br /&gt;
    from time import clock&lt;br /&gt;
    x = GeoLiteDB()&lt;br /&gt;
    x.connect();&lt;br /&gt;
    begin = clock()&lt;br /&gt;
    x.ipLocation(&amp;quot;84.108.189.94&amp;quot;);&lt;br /&gt;
    end = clock()&lt;br /&gt;
    x.close()&lt;br /&gt;
    return end - begin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def createDB(dbPath = &amp;#039;geolite.db&amp;#039;, locationsPath=&amp;#039;GeoLiteCity-Location.csv&amp;#039;, blocksPath=&amp;#039;GeoLiteCity-Blocks.csv&amp;#039;, warnOnDelete = True):&lt;br /&gt;
    if os.path.exists(dbPath):&lt;br /&gt;
        if warnOnDelete:&lt;br /&gt;
	    print &amp;quot;file %s will be deleted. Press any key to continue, or &amp;#039;n&amp;#039; to abort...&amp;quot; % (os.path.abspath(dbPath))&lt;br /&gt;
	    if getch() == &amp;#039;n&amp;#039;:&lt;br /&gt;
	        print &amp;#039;aborted.&amp;#039;&lt;br /&gt;
	        return None&lt;br /&gt;
	os.remove(os.path.abspath(dbPath))&lt;br /&gt;
    conn = sqlite.connect(dbPath)&lt;br /&gt;
    cursor = conn.cursor()&lt;br /&gt;
    try:&lt;br /&gt;
        cursor.execute(&amp;#039;&amp;#039;&amp;#039;CREATE TABLE locations(&lt;br /&gt;
				locid	INTEGER PRIMARY KEY,&lt;br /&gt;
				country TEXT,&lt;br /&gt;
				region	TEXT,&lt;br /&gt;
				city	TEXT,&lt;br /&gt;
				postalCode TEXT,&lt;br /&gt;
				latitude REAL,&lt;br /&gt;
				longitude REAL,&lt;br /&gt;
				dmaCode INTEGER,&lt;br /&gt;
				areaCode INTEGER)&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	cursor.execute(&amp;#039;&amp;#039;&amp;#039;CREATE TABLE blocks(&lt;br /&gt;
				startIpNum INTEGER,&lt;br /&gt;
				endIpNum INTEGER,&lt;br /&gt;
				locId INTEGER)&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	locations = file(locationsPath,&amp;#039;r&amp;#039;)&lt;br /&gt;
	print (&amp;#039;parsing locations. This will a while.&amp;#039;)&lt;br /&gt;
	print locations.readline().strip() #should print copyright note&lt;br /&gt;
        print locations.readline().strip() #should print column names&lt;br /&gt;
        lines = ([x.strip(&amp;#039;&amp;quot;&amp;#039;) for x in line.strip().split(&amp;#039;,&amp;#039;)] for line in locations.xreadlines())&lt;br /&gt;
        cursor.executemany(&amp;#039;insert into locations values (?,?,?,?,?,?,?,?,?)&amp;#039;, lines)&lt;br /&gt;
	locations.close()&lt;br /&gt;
&lt;br /&gt;
	blocks = file(blocksPath,&amp;#039;r&amp;#039;)&lt;br /&gt;
	print (&amp;#039;parsing blocks. This will take longer.&amp;#039;)&lt;br /&gt;
	print blocks.readline().strip() #should print copyright note&lt;br /&gt;
        print blocks.readline().strip() #should print column names&lt;br /&gt;
        lines = ([x.strip(&amp;#039;&amp;quot;&amp;#039;) for x in line.strip().split(&amp;#039;,&amp;#039;)] for line in blocks.xreadlines())&lt;br /&gt;
	cursor.executemany(&amp;#039;insert into blocks values (?,?,?)&amp;#039;, lines)&lt;br /&gt;
	blocks.close()&lt;br /&gt;
&lt;br /&gt;
#        cursor.execute(&amp;#039;&amp;#039;&amp;#039;CREATE UNIQUE INDEX startIpNumIx ON blocks(startIpNum);&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
#	cursor.execute(&amp;#039;&amp;#039;&amp;#039;CREATE UNIQUE INDEX endIpNumIx ON blocks(endIpNum);&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
        conn.commit()&lt;br /&gt;
&lt;br /&gt;
	print &amp;#039;analyze&amp;#039;&lt;br /&gt;
	cursor.execute(&amp;#039;&amp;#039;&amp;#039;ANALYZE;&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
        numBlocks = cursor.execute(&amp;#039;select count(*) from blocks&amp;#039;).fetchone()[0]&lt;br /&gt;
	numLocations = cursor.execute(&amp;#039;select count(*) from locations&amp;#039;).fetchone()[0]&lt;br /&gt;
&lt;br /&gt;
	return numBlocks, numLocations&lt;br /&gt;
&lt;br /&gt;
    finally:&lt;br /&gt;
	cursor.close()&lt;br /&gt;
        conn.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class GeoLiteDB:&lt;br /&gt;
    def __init__(self, dbPath = &amp;#039;geolite.db&amp;#039;):&lt;br /&gt;
        self.dbPath = dbPath&lt;br /&gt;
	self._conn = None&lt;br /&gt;
	self._cursor = None&lt;br /&gt;
&lt;br /&gt;
    def connect(self):&lt;br /&gt;
        if self._conn:&lt;br /&gt;
            raise &amp;#039;database already opened&amp;#039;&lt;br /&gt;
        self._conn = sqlite.connect(self.dbPath)&lt;br /&gt;
	self._cursor = self._conn.cursor()&lt;br /&gt;
    def close(self):&lt;br /&gt;
         if not self._conn:&lt;br /&gt;
	      raise &amp;#039;databse was not opened&amp;#039;&lt;br /&gt;
	 self._cursor.close()&lt;br /&gt;
         self._conn.close()&lt;br /&gt;
    def autoConnect(self):&lt;br /&gt;
        if not self._conn:&lt;br /&gt;
	    self.connect()&lt;br /&gt;
    def countBlocks(self):&lt;br /&gt;
        self.autoConnect()&lt;br /&gt;
        return self._cursor.execute(&amp;#039;select count(*) from blocks&amp;#039;).next()[0]&lt;br /&gt;
    def countLocations(self):&lt;br /&gt;
        self.autoConnect()&lt;br /&gt;
        return self._cursor.execute(&amp;#039;select count(*) from locations&amp;#039;).next()[0]&lt;br /&gt;
    def ipLocation(self, ip):&lt;br /&gt;
        self.autoConnect()&lt;br /&gt;
        if isinstance(ip,str):&lt;br /&gt;
            ip = dottedQuadToNum(ip)&lt;br /&gt;
        return cursorToDict(self._cursor.execute(&amp;#039;select * from blocks,locations where locations.locid = blocks.locid AND ? &amp;gt;= blocks.startIpNum AND ? &amp;lt;= blocks.endIpNum&amp;#039;, [ip,ip]))&lt;br /&gt;
&lt;br /&gt;
#cross platform getch, from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892&lt;br /&gt;
class _Getch:&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Gets a single character from standard input.  Does not echo to the&lt;br /&gt;
screen.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        try:&lt;br /&gt;
            self.impl = _GetchWindows()&lt;br /&gt;
        except ImportError:&lt;br /&gt;
            self.impl = _GetchUnix()&lt;br /&gt;
&lt;br /&gt;
    def __call__(self): return self.impl()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class _GetchUnix:&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        import tty, sys&lt;br /&gt;
&lt;br /&gt;
    def __call__(self):&lt;br /&gt;
        import sys, tty, termios&lt;br /&gt;
        fd = sys.stdin.fileno()&lt;br /&gt;
        old_settings = termios.tcgetattr(fd)&lt;br /&gt;
        try:&lt;br /&gt;
            tty.setraw(sys.stdin.fileno())&lt;br /&gt;
            ch = sys.stdin.read(1)&lt;br /&gt;
        finally:&lt;br /&gt;
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)&lt;br /&gt;
        return ch&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class _GetchWindows:&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        import msvcrt&lt;br /&gt;
&lt;br /&gt;
    def __call__(self):&lt;br /&gt;
        import msvcrt&lt;br /&gt;
        return msvcrt.getch()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
getch = _Getch()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
</feed>