8000 ipaddress package · robbyoconnor/practice-python@839b3ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 839b3ef

Browse files
committed
ipaddress package
1 parent d9e3412 commit 839b3ef

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

experiments/ip.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import ipaddress
2+
3+
4+
def main():
5+
my_ip = '216.58.194.206'
6+
7+
print(my_ip)
8+
9+
addr = ipaddress.ip_address(my_ip)
10+
11+
print(ipaddress.ip_network(my_ip))
12+
print('Compressed: ', addr.compressed)
13+
print('Exploded: ', addr.exploded)
14+
print('Packed: ', addr.packed)
15+
print('As int: ', int(addr))
16+
print('As binary: ', bin(int(addr)))
17+
18+
print('-------------------')
19+
20+
network_mask = '192.0.2.0/24'
21+
print('Network mask: ', network_mask)
22+
print('Network subnets: ', list(ipaddress.ip_network(network_mask).subnets()))
23+
24+
25+
if __name__ == '__main__':
26+
main()

0 commit comments

Comments
 (0)
0