-2

I have subnet address and mask, and I am looking for possible IP range in that subnet. Please let me know a solution in Python, PHP, or Java.

For example, I have the following details:

Subnet address: 10.113.12.40

mask: 255.255.255.248

Then what will be the IP Range?

JS.
  • 14,781
  • 13
  • 63
  • 75
user2486495
  • 1,709
  • 11
  • 19
  • Python has this library: http://docs.python.org/dev/library/ipaddress which might be of interest to you – karthikr Jun 14 '13 at 14:48
  • it doesn't seem like you tried something.. but as a starting point.. this php function http://php.net/ip2long turns an IPv4 address to a number.. from that point on I am guessing that it's a matter of subtracting/adding the right values – mishu Jun 14 '13 at 14:50

1 Answers1

10
 10.113. 12. 40 -> 00001010.01110001.00001100.00101000
255.255.255.248 -> 11111111.11111111.11111111.11111000
                                                   ^^^--- 3 bits for your network

2**3 = 8, so you've got 8 IPs in your network, giving you a range of 10.113.12.40 -> 10.113.12.47

Basically a netmask defines what's "inside" and "outside" your network. Normal bitmask has 1 for outside, and 0 for inside. So a quicker version would be:

10.113.12.40 NOR 255.255.255.248 = 10.113.12.47
               ^^^^^^^^^^^^^^^---invert the mask and OR it with the network address.
Marc B
  • 356,200
  • 43
  • 426
  • 500