linux批量查询ip归属地

#!/bin/bash  
for i in `cat /root/ip/1.txt`
do
ip_address=`curl -A "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" \
    -s "http://ip138.com/ips138.asp?ip="$i"&action=2" |\
    iconv -f gb2312 -t utf-8 |\
    grep "class" |\
    awk '{n=split($0,a,"

  • ");for(i=2;i     sed 's/<\/li>//g' |\
        sed -n '1p;3p'`
    echo -e $i "\n"  $ip_address  >> /root/ip/2.txt
    done
     

  • 你可能感兴趣的:(linux批量查询ip归属地)