gpt4 book ai didi

python - 通过IP和掩码计算广播

转载 作者:太空狗 更新时间:2023-10-30 02:38:21 24 4
gpt4 key购买 nike

<分区>

我正在尝试使用指定的 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)))

screenshot

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com