生产实践:
利用淘宝IP库批量查询IP信息
学习技巧:
shell脚本并行执行
脚本内容:
#!/bin/bash
############################################################
# $Name: ip.sh
# $Version: v1.0
# $Function: use Taobao IP address library(http://ip.taobao.com) to query the IP info
# $Author: Zhihe An
# $organization: chegva.com
# $Create Date: 2017-09-23
############################################################
printf "%-18s\t%-8s %-8s %-8s %-9s %-8s\n" IP地址 国家 运营商 区域 省份 城市
echo -e "\e[1;33m===========================================================================\e[0m"
for i in `cat list`
do
{
./tbip.py $i
sleep 1
}&
done
wait◎python脚本
#!/usr/bin/env python # coding=utf8 import urllib2 import json import sys ip = sys.argv[1] ip_tb_api_url = "http://ip.taobao.com/service/getIpInfo.php?ip=" f = urllib2.urlopen(ip_tb_api_url + ip) result = json.loads(f.read()) area = result["data"]["area"] city = result["data"]["city"] country = result["data"]["country"] isp = result["data"]["isp"] region = result["data"]["region"] print "%-23s %-8s %-8s %-8s %-8s %-8s" %(ip, country, isp, area, region, city)
◎查看效果
