Package: netlookup
Command line network lookups and operationsThis python tool implements pretty much same things asnetcalcandnetblockslibraries, but
with minor differences in the way things are done.The library is intended to be usable both as a command line toolnetlookupand as a library from
server code. Personally I use it for splitting IP ranges to subnets.InstallingpipinstallnetlookupCommand line toolnetlookupbasic usageFollowing examples illustrate Usage of netlookup tool.Lookup details for IPv4 host with CIDR mask and IPv6 subnet:netlookupinfo172.31.1.19/172c0f:fb50:4000::/56CIDR172.31.0.0/17Netmask255.255.128.0Network172.31.0.0Broadcast172.31.127.255Firsthost172.31.0.1Lasthost172.31.127.254Totalhosts32766Next172.31.128.0/17Previous172.30.128.0/17Bits10101100.00011111.00000000.00000000ReverseDNS0.0.31.172.in-addr.arpa.CIDR2c0f:fb50:4000::/56Netmaskffff:ffff:ffff:ff00::Network2c0f:fb50:4000::Broadcast2c0f:fb50:4000:ff:ffff:ffff:ffff:ffffFirsthost2c0f:fb50:4000::1Lasthost2c0f:fb50:4000:ff:ffff:ffff:ffff:fffeTotalhosts4722366482869645213694Next2c0f:fb50:4000:100::/56Previous2c0f:fb50:3fff:ff00::/56Bits0010110000001111:1111101101010000:0100000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000ReverseDNS0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.0.5.b.f.f.0.c.2.ip6.arpa.Split subnet with defaults (to next smaller subnet / larger prefix):netlookupsplit172.31.1.19/172c0f:fb50:4000::/56172.31.0.0/18172.31.64.0/182c0f:fb50:4000::/572c0f:fb50:4000:80::/57Split IPv4 subnets with specific prefix:netlookupsplit--mask19172.31.1.19/17172.31.5.39/17172.31.0.0/19172.31.32.0/19172.31.64.0/19172.31.96.0/19172.31.0.0/19172.31.32.0/19172.31.64.0/19172.31.96.0/19Using the python librarySome practical examples for using the API where a CLI command is not yet available.Create set of networks and show minimal merged CIDR prefixes to cover this range:fromnetlookup.network_sets.baseimportNetworkSetns=NetworkSet()ns.add_network('172.31.0.0/23')ns.add_network('172.31.4.0/22')ns.add_network('172.31.8.0/24')ns.add_network('172.31.9.0/25')ns.add_network('172.31.9.128/25')print('\n'.join(str(x.cidr)forxinns.merged))Previous example returns172.31.0.0/23172.31.4.0/22172.31.8.0/23Using same example, remove one /29 from the result setfromnetlookup.network_sets.baseimportNetworkSetns=NetworkSet()ns.add_network('172.31.0.0/23')ns.add_network('172.31.4.0/22')ns.add_network('172.31.8.0/24')ns.add_network('172.31.9.0/25')ns.add_network('172.31.9.128/25')print('\n'.join(str(x.cidr)forxinns.substract('172.31.8.64/29')))This example returns172.31.0.0/23172.31.4.0/22172.31.8.0/26172.31.8.72/29172.31.8.80/28172.31.8.96/27172.31.8.128/25172.31.9.0/24Cloud vendor prefixesThis tool contains lookup caches for some cloud vendors. Currently supported vendors are:AWSCloudflareGoogle CloudGoogle ServicesNote: Azure support was removed because their data is in a silly URL and I just don't
care about them.Example to load data for cloud vendor IP prefix lookups and save it to user specific cache
directory~/.config/netlookup.Following command requires internet connection to update the prefix lists.fromnetlookup.prefixesimportPrefixesns=Prefixes()print(ns.cache_directory)ns.update()ns.save()Get prefixes for cloud vendorsUse the previously loaded cached cloud vendor IP prefix lookup and find some addresses.>>>ns.find('3.81.2.1')awsus-east-13.80.0.0/12Similarly, you can get specific vendor network set and lookup address from there:>>>ns.get_vendor('google').find('216.58.210.142')google216.58.192.0/19