NetCIDR 0.1 Released

Posted on January 29, 2006 by oubiwann


Blog post image

networking :: python :: programming


As part of the on-going work with
CoyoteMonitoring,
NetCIDR
was written to allow for a clean and logical approach when analyzing
NetFlow
captures. Primarily, it's use is for determining whether a given IP
address is in a given netblock or a collection of netblocks. Here are
some quick example usages from the wiki and doctests:


>>> CIDR('10.4.1.2')
10.4.1.2
>>> CIDR('10.4.1.x')
10.4.1.0/24
>>> CIDR('10...*')
10.0.0.0/8
>>> CIDR('172.16.4.28/27')
172.16.4.28/27
>>> CIDR('172.16.4.28/27').getHostCount()
32

Here's how you create a collection of networks:


>>> netcidr = CIDR('192.168.4.0/24')
>>> corp
cidr = CIDR('10.5.0.0/16')
>>> vpn_cidr = CIDR('172.16.9.5/27')
>>> mynets = Networks([netcidr, corpcidr])
>>> mynets.append(vpn_cidr)

And now, you can check for the presence of hosts in various networks
and/or collections of networks:


>>> home_router = CIDR('192.168.4.1')
>>> laptop1 = CIDR('192.168.4.100')
>>> webserver = CIDR('10.5.10.10')
>>> laptop2 = CIDR('172.16.9.17')
>>> laptop3 = CIDR('172.16.5.17')
>>> google = CIDR('64.233.187.99')

>>> home_router in mynets
True
>>> laptop1 in mynets
True
>>> webserver in mynets
True
>>> laptop2 in mynets
True
>>> laptop3 in mynets
False
>>> google in mynets
False


Author oubiwann
Date January 29, 2006
Time 07:14:08
Category
Tags
Line Count 1
Word Count 217
Character Count 2074

Comments?
This blog doesn't use standard (embedded) comments; however, since the site is hosted on Github, if there is something you'd like to share, please do so by opening a "comment" ticket!