Python里有一个专门处理该类问题的IP类库,来看看:

#! /usr/bin/env python

import sys
from IPy import IP

address = sys.argv[1]
netmask = sys.argv[2]

#print address,netmask

#help(IP)
networkAddress = IP(address).make_net(netmask) # init a IP instance, can with netmask directly, or use make_net(netmask)
bcastAddress = IP(networkAddress).broadcast() # return the broadcast ip address

print networkAddress
print bcastAddress

版权声明:本文为maodouzi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/maodouzi/archive/2010/05/16/1736827.html