Browse Source

ip geolocation progress

pull/8/head
Andrew Marcuse 4 years ago
parent
commit
fa49208a4c
  1. 44
      data/domain-suffix.txt
  2. 15
      run.sh
  3. 10
      src/server.ts
  4. 55
      views/iplocation.hbs

44
data/domain-suffix.txt

@ -0,0 +1,44 @@
am
at
blue
buzz
cloud
com
cool
dev
es
express
fan
fyi
guru
host
in
info
ink
io
is
ist
it
link
lv
me
monster
ninja
one
onl
online
org
pub
plus
red
rocks
run
sh
site
tech
to
tools
uno
world
xyz
zone

15
run.sh

@ -1,8 +1,19 @@
#!/bin/bash
#!/usr/bin/env bash
#
# run server locally
#
export $(cat .env)
set -o errexit
set -o pipefail
set -o nounset
#
# load an .env file if it exists
#
ENV_FILE="./.env"
if [ -f "${ENV_FILE}" ]; then
echo "INFO: loading '${ENV_FILE}'!"
export $(cat "${ENV_FILE}")
fi
npx nodemon

10
src/server.ts

@ -172,12 +172,18 @@ rootRouter.get('/headers.html', async (ctx:any) => {
});
rootRouter.get('/iplocation.html', async (ctx:any) => {
let ip = ctx.request.query['ip'] || ctx.request.body.ip;
const current_ip = ctx.ips.length > 0 ? ctx.ips[0] : ctx.ip;
const current_location = await asn.cityLookupStr(current_ip);
if (!ip) {
ip = current_ip;
}
const maxmind = await asn.cityLookupStr(ip);
ctx.body = await ctx.render('iplocation.hbs', {
current_ip,
current_location,
maxmind,
ip,
title: 'IP Address Geolocation',
});
});

55
views/iplocation.hbs

@ -1,3 +1,58 @@
{{> above}}
<div class="alert alert-info">Geolocating an IP address is not an exact science. It depends on data collected (or volunteered)
by the community, and needs constant updates.
</div>
<h2>Results for {{ip}}</h2>
<table class="table table-striped border-bottom">
<thead>
<tr>
<th>Provider</th>
<th>Version</th>
<th>Results</th>
</tr>
</thead>
<tbody>
<tr>
<td>Maxmind</td>
<td>{{maxmind_version}}</td>
<td>{{maxmind}}</td>
</tr>
<!--
<tr>
<td>HostIP.info</td>
<td><i>(online service)</i></td>
<td>{{hostipinfo}}</td>
</tr>
-->
</tbody>
</table>
<h2>Specific IP</h2>
<div class="row">
<div class="col d-flex justify-content-center">
<div class="card col-lg-5 px-0">
<div class="card-body">
<h5 class="card-title text-center">IP Geolocation</h5>
<div class="form-group">
<label for="ip">IP Address</label>
<input type="text" class="form-control" id="ip" name="ip" value="{{ip}}" />
</div>
<input class="btn btn-primary" type="submit" value="Locate" />
</div>
</div>
</div>
</div>
<hr/>
<h2>Other IP Geolocation Databases</h2>
<div class="alert alert-info">
Note: all pricing is for the lowest service level possible. They all have higher priced options (of course).
</div>
{{> below}}
Loading…
Cancel
Save