Linux Bash Lookup Geo Location From IP

View previous topic View next topic Go down

Linux Bash Lookup Geo Location From IP

Post by jamied_uk on 24th May 2016, 08:12

Code:
sudo apt-get install -y geoip-bin geoip-database




Code:

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

wget http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz

gunzip GeoIP.dat.gz

gunzip GeoIPASNum.dat.gz

gunzip GeoLiteCity.dat.gz

sudo cp GeoIP.dat GeoIPASNum.dat GeoLiteCity.dat /usr/share/GeoIP/



geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat 23.66.166.151
avatar
jamied_uk
Admin

Posts : 2193
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Linux Bash Lookup Geo Location From IP

Post by jamied_uk on 24th May 2016, 08:21

Very Optimized and quick ip lookup


Code:
#!/usr/bin/env bash
# sudo apt-get install -y geoip-bin geoip-database
#
# Usage: ./quick_ip_lookup.sh 74.125.225.33
input=$1
#
geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $input


Update Code
https://app.box.com/s/q2h5yjtybtuf5fi2havbbz2po4p8dxdt


Code:
#!/usr/bin/env bash
# geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $input
# ./quick_log.sh
# http://jnet.forumn.biz/post?p=1653&mode=editpost
# http://kbeezie.com/geoiplookup-command-line/
cat /var/log/apache2/access.log | awk '{print $1}' > ips.txt
uniq ips.txt > uniqips.txt
IPS=`cat uniqips.txt`
for i in $IPS
do
  echo "$i,`geoiplookup $i  | cut -d "," -f2 | sed -e 's/^[\t]//'`" >> ipinfo.csv
done




You may need to use su
for super user account access before
Code:
./quick_log.sh


Last edited by jamied_uk on 25th May 2016, 16:12; edited 1 time in total
avatar
jamied_uk
Admin

Posts : 2193
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Linux Bash Lookup Geo Location From IP

Post by jamied_uk on 24th May 2016, 10:36

For Converting CSV To JSON


https://automatetheboringstuff.com/chapter14

Or

https://encrypted.google.com/search?q=csv+#safe=off&q=csv+to+json+python

https://gist.github.com/chrislkeller/4700210


Online Conversion

http://www.convertcsv.com/csv-to-json.htm
avatar
jamied_uk
Admin

Posts : 2193
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Linux Bash Lookup Geo Location From IP

Post by jamied_uk on 6th June 2016, 03:09

PHP Script to do this on a linux server using shell command

Code:
<center>
<?php
$ip = $_GET['ip'];
$process = shell_exec("geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $ip");

$rem = array("GeoIP City Edition, Rev 1:", " N/A,");
$rep = "";
echo $process = str_replace($rem,$rep,$process);
echo "<p>";

$new = substr("$process",5,-7);
echo '<p><br><a href="https://www.google.co.uk/maps/search/'.$new.'" target="_blank">Find On Map</a>';
?>
avatar
jamied_uk
Admin

Posts : 2193
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Linux Bash Lookup Geo Location From IP

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum