【发布时间】:2020-09-01 14:45:51
【问题描述】:
我想在 python 中使用 ipaddress 和和子网掩码之间的按位运算来查找网络 ID。我想用这种传统方法我的示例代码在这里
hostname=input("Enter the IP Address: ")
print(hostname)
if hostname >= "0.0.0.0" and hostname <= "127.255.255.255":
print("Class A")
print("The default subnet mask is: 255.0.0.0")
j=(hostname & 255.0.0.0)
print("The network id is ",j)
【问题讨论】:
-
Edit 标记您使用的语言,解释运行此代码时会发生什么,并解释为什么结果不正确或不充分。 (这可能是因为您尝试使用没有真正意义的字符串做一些事情,需要先转换为整数。)
标签: python ip-address