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
Want i am trying to achive is the lookup to be something like this
I am open to suggestions, or better ways of doing this
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/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)]) |
1 2 3 |
ip_to_name = { '10.21.32.0/24' - '10.21.36.0/24 : ' Site1', } |
Many thanks