通过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 http://www.ip168.com/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 "http://www.ip138.com/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)
while read line
do
echo $line
ip=$(echo -en $line | awk '{print $3}' | awk -F"/" '{print $1}')
echo $ip
add=$(wget -q http://www.ip168.com/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 "http://www.ip138.com/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)