![]() |
Subnet Mask Ranges - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Subnet Mask Ranges (/thread-16705.html) |
Subnet Mask Ranges - ab52 - Mar-11-2019 Hi All I am very new to python, and i have written something that grabs your IP and returns coverts it into the subnet mask and then give it a friendly name What i am stuck on is have a range of subnet Here is what i have done #!/usr/bin/env python import ipaddress import socket ip_to_name = { '10.21.32.0/24' : 'Site1', } host_name = socket.gethostname() host_ip = socket.gethostbyname(host_name) net = ipaddress.ip_network(u'{0}/255.255.255.0'.format(host_ip), strict=False) print(ip_to_name[str(net)])Want i am trying to achive is the lookup to be something like this ip_to_name = { '10.21.32.0/24' - '10.21.36.0/24 : 'Site1', }I am open to suggestions, or better ways of doing this Many thanks |