networking :: python :: programming
and/or collections of networks:
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:
Here's how you create a collection of networks:
>>> 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
And now, you can check for the presence of hosts in various networks
>>> net_cidr = CIDR('192.168.4.0/24')
>>> corp_cidr = CIDR('10.5.0.0/16')
>>> vpn_cidr = CIDR('172.16.9.5/27')
>>> mynets = Networks([net_cidr, corp_cidr])
>>> mynets.append(vpn_cidr)
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
No comments:
Post a Comment