cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post

Class C Subnet device count

This is a quick SQL code to count the number of devices within a /24 subnet.  I'm sure it can be expanded to accomindate any cidr.

SELECT

  SUBSTRING(IP_Address, 1, LEN(IP_Address) - CHARINDEX('.', REVERSE(IP_Address)))+'.0/24' as [Subnet],

  COUNT(*) as [Count]

  FROM nodes

  GROUP BY SUBSTRING(IP_Address, 1, LEN(IP_Address) - CHARINDEX('.', REVERSE(IP_Address)))

  order by [count] desc

pastedImage_0.png

Thanks

Amit

Tags (2)
Version history
Revision #:
1 of 1
Last update:
‎11-08-2017 12:29 PM
Updated by: