作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<分区>
我正在尝试使用指定的 ip 和掩码通过逻辑 OR 和 NOT 来计算广播地址,但是 func 返回给我 smth 奇怪。为什么?
IP = '192.168.32.16'
MASK = '255.255.0.0'
def get_ID(ip, mask):
ip = ip.split('.')
mask = mask.split('.')
ip = [int(bin(int(octet)), 2) for octet in ip]
mask = [int(bin(int(octet)), 2) for octet in mask]
subnet = [str(int(bin(ioctet & moctet), 2)) for ioctet, moctet in zip(ip, mask)]
host = [str(int(bin(ioctet & ~moctet), 2)) for ioctet, moctet in zip(ip, mask)]
broadcast = [str(int(bin(ioctet | ~moctet), 2)) for ioctet, moctet in zip(ip, mask)] # a mistake, i guess
print('Subnet: {0}'.format('.'.join(subnet)))
print('Host: {0}'.format('.'.join(host)))
print('Broadcast address: {0}'.format('.'.join(broadcast)))
我是一名优秀的程序员,十分优秀!