PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Linux Bash Lookup Geo Location From IP

Go down

Linux Bash Lookup Geo Location From IP Empty Linux Bash Lookup Geo Location From IP

Post by jamied_uk 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
jamied_uk
jamied_uk
Admin

Posts : 2950
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Linux Bash Lookup Geo Location From IP Empty Re: Linux Bash Lookup Geo Location From IP

Post by jamied_uk 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.forumotion.com/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
jamied_uk
jamied_uk
Admin

Posts : 2950
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Linux Bash Lookup Geo Location From IP Empty Re: Linux Bash Lookup Geo Location From IP

Post by jamied_uk 24th May 2016, 10:36

jamied_uk
jamied_uk
Admin

Posts : 2950
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Linux Bash Lookup Geo Location From IP Empty Re: Linux Bash Lookup Geo Location From IP

Post by jamied_uk 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>';
?>
jamied_uk
jamied_uk
Admin

Posts : 2950
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Linux Bash Lookup Geo Location From IP Empty Re: Linux Bash Lookup Geo Location From IP

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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