Skip to content

Commit

Permalink
add maxmind database
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Nov 5, 2023
1 parent ce2a63b commit 7841275
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docs/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ var drawMap = function () {
if (url.includes('YOUR-APIKEY')) {
continue;
}
let proxy = false;
if (url.startsWith('https://geoipproxy.emrik.org/')) {
proxy = true;
}

fetchAndDisplay(api, url, ip, false)
fetchAndDisplay(api, url, ip, proxy)
}
})
.then(() => {
Expand Down
12 changes: 12 additions & 0 deletions docs/sites.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,17 @@
"server": "https://ipinfo.io/8.8.8.8?token=5fd5a2efa76b59",
"https": true,
"limit": "50000/month"
},
"geolite2": {
"homepage": "https://dev.maxmind.com/geoip/geoip2/geolite2/",
"server": "https://geoipproxy.emrik.org/geolite2/8.8.8.8",
"https": true,
"limit": "n/a"
},
"geoip2": {
"homepage": "https://www.maxmind.com/en/geoip2-city-database",
"server": "https://geoipproxy.emrik.org/geoip2/8.8.8.8",
"https": true,
"limit": "16667/account"
}
}
102 changes: 102 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@maxmind/geoip2-node": "^4.2.0",
"axios": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^16.1.4",
Expand Down
25 changes: 24 additions & 1 deletion proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const express = require('express');
const cors = require('cors')
const sites = require('./docs/sites.json');
const axios = require('axios');
const WebServiceClient = require('@maxmind/geoip2-node').WebServiceClient;
require('dotenv').config()
const geoipKey = process.env["maxmind.com"]
const maxmindaccount = process.env["maxmind.com.account"]
const geoipClient = new WebServiceClient(maxmindaccount, geoipKey);
const geoliteClient = new WebServiceClient(maxmindaccount, geoipKey, { host: 'geolite.info' });

const app = express();
const port = 3000;
Expand All @@ -10,7 +16,24 @@ app.use(cors())
app.get('/:site/:ip', (req, res) => {
const site = req.params.site;
const ip = req.params.ip;
if (site in sites) {

if (site == 'geoip2') {
geoipClient.city(ip)
.then(response => {
res.send(response);
})
.catch(error => {
res.send('Error with request to ' + site);
});
} else if (site == 'geolite2') {
geoliteClient.city(ip)
.then(response => {
res.send(response);
})
.catch(error => {
res.send('Error with request to ' + site);
});
} else if (site in sites) {
let url = sites[site]["server"].replace('8.8.8.8', ip);

// fetch url and return response
Expand Down

0 comments on commit 7841275

Please sign in to comment.