0

i have found the IP range 120.76.0.0 - 120.79.255.255 that i want to ban in iptables the way i write x.x.x.x/xx format. Please how to know what that x.x.x.x/xx should be? I have found some online tool where i enter the range and it return it, but unable, these tools like https://www.calculator.net/ip-subnet-calculator.html only have field for single IP and subnet mask.

Update: currently this calculator should work: https://community.spiceworks.com/tools/subnet-calc/ and set "Number of subnets" to 1

16851556
  • 101
  • 3

1 Answers1

1

First keep in mind that a range is a set of arbitrary contiguous IP address and does not always match a CIDR network.

In your case it does, though.

So what you need is to find the smallest 'supernet` of the two addresses.

To do so you can refer to my answer here.

Doing the math for your range we get:

120.76.0.0 = 01111000.01001100.00000000.00000000
120.79.255.255 = 01111000.01001111.11111111.11111111

The common part is 01111000.010011, I.E. 14 bits long

So your network is 01111000.01001100.00000000.00000000 /14 = 120.76.0.0/14

The broadcast address is the network address + all 1 in the host part. I.E. 01111000.01001111.11111111.11111111 which is the last address in your range.

Conclusion :
the IP range IP range 120.76.0.0 - 120.79.255.255 correspond to 120.76.0.0/14

JFL
  • 19,649
  • 1
  • 32
  • 64