ip转c段

# -*- coding: UTF-8 -*-
import IPy


def ipToC():
    ips = set()
    readPath = 'ip.txt'
    writePath = 'ip_c.txt'
    outFile = open(writePath, 'w')
    with open(readPath, 'r') as f:
        for line in f:
            ip = line.strip('\n')
            ip_c = IPy.IP(ip).make_net('255.255.255.0')
            if ip_c not in ips:
                outFile.write(str(ip_c) + '\n')
                ips.add(ip_c)
    outFile.close()
    print('转换结束')


if __name__ == '__main__':
    ipToC()

ip转c段_第1张图片

你可能感兴趣的:(red,tcp/ip,网络,服务器,python)