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
Many thanks
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 thisMany thanks
