forked from jwasham/practice-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip.py
More file actions
26 lines (17 loc) · 583 Bytes
/
ip.py
File metadata and controls
26 lines (17 loc) · 583 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import ipaddress
def main():
my_ip = '216.58.194.206'
print(my_ip)
addr = ipaddress.ip_address(my_ip)
print(ipaddress.ip_network(my_ip))
print('Compressed: ', addr.compressed)
print('Exploded: ', addr.exploded)
print('Packed: ', addr.packed)
print('As int: ', int(addr))
print('As binary: ', bin(int(addr)))
print('-------------------')
network_mask = '192.0.2.0/24'
print('Network mask: ', network_mask)
print('Network subnets: ', list(ipaddress.ip_network(network_mask).subnets()))
if __name__ == '__main__':
main()