python - Compairing a list and extracting a number -


I'm trying to get a list containing the IP address' with subnet mask (1.0.0.0/24) And the total number of IP addresses in that list 'However, I am trying to avoid compiling the same IP address, but there is a high subnet mask.

Example 1.0.0.0/24 1.0.0.0/16 1.0.0.0/8

I would like to use I / 8 to calculate the IP address / because in it / 16 And / 24

I have put all IP addresses in a list, such as, the newset ...

Example 1.0.0.0/24 1.0.0.0/16 1.0.0.0 / 8 2.0.0.0/24 2.0.0.0/16 etc ....

Then I use the following code to pop up subnet masks / 24, / 16, / 8 etc.

then by ipTotal for example

  subIP = [i.split ('/', 1) [1] i) Gps of ip space I am declaring the universal  
  for element in subtype: y = 32 - int (element) x = pow (2, y) ipTotal = ipTotal + x  

But now I'm counting 1.0.0.0/24, 1.0.0.0/16 and 1.0.0.0/8, when I only do everything to calculate 1.0.0.0/8.

Actually I am calculating the amount of IP space.

How do I need to reach it? I thought of putting 1.0.0.0 in a list, then put 24/24 in another list ... then the nested is going to compare to the loop, but I'm pretty sure this will not work.

I am new to Ajithan so that any help would be appreciated.

  ip_dict = {} for ip_subnet in newSet: Ip, subnet = ip_subnet.split ( '/') Subnet = int (subnet) if ip_dict or ip_dict [ip] & gt; Subnet: ip_dict [ip] iptotal = 0 ip_dict.iteritems for subnet in ip_dict.values ​​()] IP for ip, [str (ip) + "/" + str (subnet) for subnet + Y = 32 - Unique (code) key, value  coupling and just check the ones you want, then create the address again in a list. 

updated_list will be the list of IP addresses that are the smallest subnet for that IP.

ip_dict.values ​​() gives a list of subnets of those unique IPs.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -