标签: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()
标签:ror open blog rsa split txt erro color odi
原文地址:http://www.cnblogs.com/forsaken/p/7231840.html