12-04 2 views
结合ip查询网站www.cip.cc查询页面用BeautifulSoup过滤结果写的小脚本,可查单个IP归属地也可批量查IP归属地,脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import requests import argparse from bs4 import BeautifulSoup def cip(ipvalue): url = 'http://www.cip.cc/{ips}'.format(ips=ipvalue) r = requests.get(url) html = r.text soup = BeautifulSoup(html, 'html.parser') print(soup.pre.string) parser = argparse.ArgumentParser(description='IP attribution') parser.add_argument("-c", help="python3 cip.py -c 8.8.8.8") parser.add_argument("-f", help="python3 cip.py -f iplist.txt") args = parser.parse_args() if args.c: cip(args.c) elif args.f: for ip in open(args.f): cip(ip) print('==========================================') else: print("See 'cip.py -h'") |
如果想赏钱,可以用微信扫描下面的二维码,一来能刺激我写博客的欲望,二来好维护云主机的费用; 另外再次标注博客原地址 itnotebooks.com 感谢!