-4

can we create code in Python that can accept the Number of users as an input and creates an Subnetted IP with the Mask bit for an example 10.141.0.0/13 is an ip I want to add 125 users from this IP so I have to Subnet this(10.141.0.0./13) to (10.141.0.0/25) , can we create a script in Python to do this? I have a clue we can do something with the python module 'netaddr', But suggest me something to do this.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Short answer: yes.

Slightly longer answer: determine the smallest power of two minus two that is larger or equal than your node number. Calculate 32 - power for the mask size. The host mask is (2^power)-1, the network mask (2^32)-1 - host mask.

Zac67
  • 2,761
  • 1
  • 10
  • 21
  • can u please give an example.for the above concept – siva kumar Feb 13 '18 at 07:36
  • Start with 56 hosts. 56+2=58. Smallest power of two larger than that: 64. log2(64) = 6. 32-6 = 26, so it's a /26 subnet. The host mask is (2^6)-1. The network mask is ((2^32)-1) - ((2^6)-1). – Zac67 Feb 13 '18 at 10:25