Last active
May 17, 2022 07:33
-
-
Save vadirajks/8b9149d975eef25f6d9b6749df379224 to your computer and use it in GitHub Desktop.
IP lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1> | |
yum install https://github.com/maxmind/mmdbinspect/releases/download/v0.1.1/mmdbinspect_0.1.1_linux_amd64.rpm -y | |
yum install yum install https://github.com/maxmind/geoipupdate/releases/download/v4.9.0/geoipupdate_4.9.0_linux_amd64.rpm http://mirror.centos.org/centos/7/os/x86_64/Packages/GeoIP-1.5.0-14.el7.x86_64.rpm | |
#!/bin/bash | |
in_file=/tmp/bquxjob_56e85de3_180cc776473.csv | |
out_file=${in_file%%.*}-output.csv | |
mv -f ${out_file} ${out_file%%.*}-$(date +%s) 2>/dev/null | |
echo '"user_id","ip_address","country","city"' >> ${out_file} | |
for i in $(cat ${in_file}| grep -v user_id); do | |
details=$(mmdbinspect -db /usr/share/GeoIP/GeoLite2-City.mmdb ${i##*,} | jq "[.[0].Lookup,.[0].Records[0].Record.country.names.en,.[0].Records[0].Record.subdivisions[].names.en]|@csv") | |
echo "\"${i%%,*}\",$details" >> ${out_file} | |
done | |
2> replace token key <token key> | |
#!/bin/bash | |
in_file=/tmp/bquxjob_42970b7a_180cc1fd105.csv | |
out_file=${in_file%%.*}-output.csv | |
mv -f ${out_file} ${out_file%%.*}-$(date +%s) 2>/dev/null | |
echo '"user_id","ip_address","city","region","country"' >> ${out_file} | |
for i in $(cat ${in_file}| grep -v user_id); do | |
details=$(curl ipinfo.io/${i##*,}?token=<token key>| jq -c '[.ip, .city, .region, .country] | @csv') | |
echo "\"${i%%,*}\",$details" >> ${out_file} | |
done | |
3> | |
#!/bin/bash | |
in_file=/tmp/bquxjob_56e85de3_180cc776473.csv | |
out_file=${in_file%%.*}-output.csv | |
mv -f ${out_file} ${out_file%%.*}-$(date +%s) 2>/dev/null | |
echo '"user_id","ip_address","city","country"' >> ${out_file} | |
for i in $(cat ${in_file}| grep -v user_id); do | |
echo "\"${i%%,*}\",\"${i##*,}\",$(whois ${i##*,} | grep -e "Country:\|City:" | sed 's/\:.[[:space:]]*/:/g'|awk -F: 'BEGIN {ORS=","}{print "\042" $2 "\042"}'|sed 's/,$//')" >> ${out_file} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment