IP 서브넷 계산기
CIDR 블록에 대한 서브넷 마스크, 네트워크 주소, 브로드캐스트, 호스트 범위를 계산합니다.
자주 묻는 질문
코드 구현
import ipaddress
# Parse a network in CIDR notation
network = ipaddress.ip_network('192.168.1.0/24', strict=False)
print(f"Network address : {network.network_address}") # 192.168.1.0
print(f"Broadcast addr : {network.broadcast_address}") # 192.168.1.255
print(f"Subnet mask : {network.netmask}") # 255.255.255.0
print(f"Prefix length : /{network.prefixlen}") # /24
print(f"Total addresses : {network.num_addresses}") # 256
print(f"Usable hosts : {network.num_addresses - 2}") # 254
# Iterate over host addresses (excludes network and broadcast)
for host in list(network.hosts())[:3]:
print(host) # 192.168.1.1, .2, .3 ...
# Check if an IP is in the subnet
ip = ipaddress.ip_address('192.168.1.42')
print(ip in network) # True
# Split into subnets
for subnet in network.subnets(prefixlen_diff=1): # two /25 subnets
print(subnet)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.