This is free and unencumbered software released into the public domain.
Demo, enjoy!
<script src="geoLite.js" defer></script>
<script src="geoLite.datav5-20251025.js" defer></script>As always, data file is loaded after geoLite.js along with attribute defer to allow page to render.
Alternatively see geoLite.html.
Due geoLite needing to "decompress" data it can take half a second upto a second of delay before user can interact with the page.
- Fast lookup (~900k op/sec)
- Country code and name (even emoji)
- Continent code and name
- ASO ("ISP" related)
Internet connection is not required after database is loaded - it works locally.
var info = geoLite.lookup(ipAddr.value);
ipaResult.innerHTML = (
"Country: " + info.CN + " " + info.emoji + " " + info.CC + "\r\n" +
"Continent: " + info.contName + " (" + info.contCode + ")\r\n" +
"ASO: " + info.ASO
);Please avoid using this feature even though it works.
Can fail if using ipv6 (VPN/Tor or similar).
// it will attempt to fetch ip from multiple sources until one is retrieved
geoLite.fetchPubIPv4(function(arr, xhr, url, elapsed) {
console.log("Result", arr, "from", u, "; elapsed:", elapsed, "[ms]");
});Note: geoLite already has these as default.
// code should be executed before fetchPubIPv4 is called.
// if using IPv6 then fetch will FAIL to parse
geoLite.ipFetchTimeout = 7000; // 7000 is default
geoLite.ipFetchMaxTimeout = 12000; // 12000 is default
geoLite.ipFetchURLs = ["https://icanhazip.com", "https://httpbin.org/ip"];(fyi: MiB = 1024 * 1024)
Database 20251025 is 3.31MiB (3481164 bytes; CSV size: 20.32750MiB)
Database 20241017 is 3.06MiB (3204748 bytes; CSV size: 18.45380MiB)
JS Databases: Link
Requirements:
- NodeJS or BunJS or anything that runs nodejs code.
- Install dependency:
mmdb-reader(BunJS auto installs it?) - Downloaded file
devtools/geoLite-dev.js
Steps:
- Download both ASN and City mmdb from anywhere.
- Example: P3TERX/GeoLite.mmdb
- Ensure to rename it in this format:
GeoLite2-City-{YYYYMMDD}.mmdb- Example:
GeoLite2-ASN-20230107.mmdb
- Example:
- Create folders
mmdbandcsvin the same folder of the filedevtools/geoLite-dev.js - Put
.mmdbfiles in foldermmdb- Example 1:
mmdb/GeoLite2-ASN-20230107.mmdb(for ASN) - Example 2:
mmdb/GeoLite2-City-20230107.mmdb(for City)
- Example 1:
- Edit file
devtools/geoLite-dev.js- (All below is about variable
geoLiteConfig) - Set
defaultDbDateuse this formatYYYYMMDD(example:20250930) - Set
scriptActto2to build csv and data file.
- (All below is about variable
- Save and Run the script
node geoLite-dev - Wait, usually can take upto an hour or more.
- Make sure to reset
scriptActto0once done. - Enjoy (data is built in same dir as
geoLite-dev.js)
Set geoLiteConfig.scriptAct=4 in devtools/geoLite-dev.js
Example output:
IPStart,IPCount,CountryCode,CountryName,ContinentCode,ContinentName,ASO
16777216,256,AU,Australia,OC,Oceania,CLOUDFLARENET
16777472,768,CN,China,AS,Asia,
...None at all, unless someone suggests public domain licensed library that can be used to further compress data file.