checkip.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:checkip 作者: china-shang 项目源码 文件源码
def main():
    global iprange, ipHasFind
    print("Process Sum:", ProcessSum)
    if ProcessSum > 1:
        q = Queue()
        q.put(ipHasFind)
        for i in range(ProcessSum):
            print("Start Process:", i)
            p = CheckProcess(q, iprange)
            p.start()

        try:
            with open("ip.txt", "w") as f:
                sum = 0
                while True:
                    ip = ipList.get()
                    s = ip + "|"
                    f.write(s)
                    sum += 1
                    print("All Sucess Ip:%4d" % sum)
        except (KeyboardInterrupt, SystemExit) as e:
            print("main exited")
        finally:
            file_name = "find_log" +"0"  + ".txt"
            with open(file_name) as f:
                s = f.readlines()

            d = dict([[int(i.split(":")[0]), int(i.split(":")[-1])]
                      for i in list(map(lambda x:x[:-1], s))])

            while GoodIpRange.qsize() > 0:
                nowdict = GoodIpRange.get()
                d.update(nowdict)

            with open(file_name, "w") as f:
                for i in d.items():
                    print(i[0], ":", i[1])
                    f.write(str(i[0]) + ":" + str(i[1]) + "\n")
    else:
        try:
            q = Queue()
            q.put(ipHasFind)
            loop = asyncio.get_event_loop()
            ipfactory = get_ip.ipFactory(q, iprange)
            testip = Test_Ip(loop, ipfactory)
            loop.create_task(testip.Server())
            profile.runctx(
                "loop.run_until_complete(testip.SuccessStop())",
                globals(),
                locals())
            # loop.run_until_complete(testip.SuccessStop())

        except (KeyboardInterrupt, SystemExit) as e:
            loop.create_task(testip.stop())
            loop.run_until_complete(testip.SuccessStop())

        finally:
            loop.close()
            print("Task exit")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号