通过ip168批量查询ip归属地#!/bin/bash
while read line
do
echo $line
ip=$(echo -en $line | awk '{print $3}' | awk -F"/" '{print $1}')
echo $ip
add=$(wget -q /ip/?ip=${ip} -O - | grep "本站主数据" | sed 's/^[ \t]*//' | awk -F"</div>" '{print $1}' | sed 's/<div>本站主数据://')
echo $add
echo -en $line | sed "/${ip}/s/\(.*\)/\1 $add\n/" >> ip_addr.txt
done < ip.txt
从ip138取需要用下面的替换掉上面的add
add=$(wget -q "/ips.asp?ip=210.51.61.195&action=2" -O -| iconv -f gbk -t utf-8 | grep "数据" | awk -F"ul" '{print $3}' | awk -F"</li>" '{print $1$2}' | awk -F"<li>" '{print $2"\n"$3}' | head -1)