码迷,mamicode.com
首页 > 其他好文 > 详细

IP2LOC

时间:2017-07-25 00:51:03      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:ror   open   blog   rsa   split   txt   erro   color   odi   

demo.txt
127.0.0.1:80
127.0.0.2
127.0.0.3:443
127.0.0.4
127.0.0.5:8080
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: f0rsaken

import IP
import sys

def main():
    try:
        file = sys.argv[1]
    except IndexError as e:
        print(e)
        sys.exit(1)

    try:
        with open(file, "r") as f:
            temp = f.readlines()
    except FileNotFoundError as e:
        print(e)
        sys.exit(1)

    ip_list = list()
    for t in temp:
        ip_list.append(t.strip())
    del temp

    chinese_mainland = list()
    not_chinese_mainland = list()
    for ip in ip_list:
        if IP.find(ip.split(":")[0]).split("\t")[0] == "中国" and IP.find(ip.split(":")[0]).split("\t")[1] not in ("香港", "澳门", "台湾"):
            chinese_mainland.append(ip + "\t" + IP.find(ip.split(":")[0]) + "\n")
            # chinese_mainland.append(ip + "\n")
        else:
            not_chinese_mainland.append(ip + "\t" + IP.find(ip.split(":")[0]) + "\n")
            # not_chinese_mainland.append(ip + "\n")
    del ip_list

    with open("chinese_mainland.txt", "w") as f:
        f.writelines(chinese_mainland)

    with open("not_chinese_mainland.txt", "w") as f:
        f.writelines(not_chinese_mainland)

if __name__ == "__main__":
    main()

 

IP2LOC

标签:ror   open   blog   rsa   split   txt   erro   color   odi   

原文地址:http://www.cnblogs.com/forsaken/p/7231840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!