Skip to content

IP - geoiplookup.sh

install

sudo apt install geoip-bin

run for one IP

geoiplookup {IP}

run for file with IPs

ips.txt

111.222.333.444
111.222.333.444
111.222.333.444
111.222.333.444

script

  • input file - ips.txt
  • output file - ips_country.txt
    while read ip; do
      result="$ip,$(geoiplookup "$ip")"
      echo $result
      echo $result >> ips_country.txt
    done < ips.txt
    
    sed -i 's/GeoIP Country Edition://g' ips_country.txt
    sed -i 's/ //g' ips_country.txt
    

output

111.222.333.444,CN,China
111.222.333.444,MX,Mexico
111.222.333.444,BR,Brazil
111.222.333.444,ML,Mali