-
Notifications
You must be signed in to change notification settings - Fork 11
/
parseGeoIP.sh
5 lines (4 loc) · 1.18 KB
/
parseGeoIP.sh
1
2
3
4
5
awk -F, '{print $3}' GeoLiteCity_20120207/GeoLiteCity-Location.csv | tr -d \" | sort | uniq > area.codes
for i in $(< area.codes ) ; do grep -m 1 ${i} GeoLiteCity_20120207/GeoLiteCity-Location.csv ; done | tr -d \" | awk -F, '{printf "%s %s:%s,%s\n",$1,$2,$3,$4}' | while read line ; do id=${line%% *}; description_and_country=${line##* }; description=${description_and_country##*:}; country=${description_and_country%%:*}; if [ "${description}" != "," ]; then code=${description%%,*}; place=${description##*,} ; addr=$(grep -m 1 "\"${id}\"" GeoLiteCity_20120207/GeoLiteCity-Blocks.csv | tr -d \" | awk -F, '{print $1}') ; echo -e "\t${country}.${code} = {ip=${addr}, desc=\"${country},${description}\"}," ; fi ; done
awk -F, '{print $2}' GeoLiteCity_20120207/GeoLiteCity-Location.csv | tr -d \" | sort | uniq > cc.codes
for i in $(< cc.codes ) ; do grep -m 1 ${i} GeoLiteCity_20120207/GeoLiteCity-Location.csv ; done | tr -d \" | awk -F, '{printf "%s %s\n",$1,$2}' | while read line ; do id=${line%% *}; country=${line##* }; addr=$(grep -m 1 "\"${id}\"" GeoLiteCity_20120207/GeoLiteCity-Blocks.csv | tr -d \" | awk -F, '{print $1}') ; echo -e "\t$country = {ip=${addr}, desc=\"${country}\"}," ; done