Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subnet Mask Ranges
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [loop] Exclude ranges in… range? Winfried 2 1,367 May-14-2023, 04:29 PM
Last Post: Winfried
  Delete all Excel named ranges (local and global scope) pfdjhfuys 2 1,691 Mar-24-2023, 01:32 PM
Last Post: pfdjhfuys
  How do I mask Hex value wiht 0xFF? korenron 2 4,351 Nov-23-2021, 09:13 AM
Last Post: Gribouillis
  Dictionary with ranges that have a float step value Irv1n 2 2,073 Apr-21-2021, 09:04 PM
Last Post: Yoriz
  Using boolean mask in Numpy for 3D IlikePi 0 1,471 Nov-14-2020, 10:08 PM
Last Post: IlikePi
  Two operations in two ranges salwa17 3 2,094 Jun-22-2020, 04:15 PM
Last Post: perfringo
  Saving a mask as a png file in opencv DanTheMan 1 5,604 Jan-31-2020, 09:20 AM
Last Post: ThiefOfTime
  iterating a list of ranges Skaperen 1 1,993 May-22-2019, 07:44 AM
Last Post: Gribouillis
  IP Subnet is asked from user Mahmut 1 1,924 Mar-08-2019, 10:10 AM
Last Post: Larz60+
  Create a List for Boolean Mask. leoahum 4 3,799 Oct-09-2018, 02:38 PM
Last Post: leoahum

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020