python求ipv4广播地址实现

it2024-11-07  5

python求ipv4广播地址

下面展示 实现代码,可以直接运行。

# IP和掩码 ipv4_addr = "192.168.1.1" ipv4_netmask = "255.255.255.0" # 求IP广播地址 ip = ipv4_addr.split('.') netmask = ipv4_netmask.split('.') ip = [int(bin(int(octet)),2) for octet in ip] netmask = [int(bin(int(octet)),2) for octet in netmask] # 使用异或方法最终获得广播地址 broadcast = [(ioctet | (moctet^0xff)) for ioctet, moctet in zip(ip, netmask)]
最新回复(0)