bensie / netaddr Goto Github PK
View Code? Open in Web Editor NEWFork of NetAddr: Automate the subnetting/supernetting of IP space, performing calculations on IP CIDR blocks, and other stuff
Fork of NetAddr: Automate the subnetting/supernetting of IP space, performing calculations on IP CIDR blocks, and other stuff
We recently ran into a problem with this gem where rails would not auto-load it because the namespace and filenames do not follow conventions. Ex (NetAddr
=> net_addr.rb
or netaddr.rb
=> Netaddr
.
If you are currently maintaining the gem, would you be open to a PR to add a shim that adds support for the naming convention? Ex:
in netaddr.rb
# ...
Netaddr = NetAddr
A more radical approach would be to rename the gem to net_addr
.
thanks,
aram
This should merge down to a /8:
irb(main):003:0> NetAddr.merge(['10.0.0.0/8','10.0.0.0/12'])
=> ["10.0.0.0/8", "10.0.0.0/12"]
As should this:
irb(main):009:0> NetAddr.merge(['10.0.0.0/8','10.0.0.0/16'])
=> ["10.0.0.0/8", "10.0.0.0/16"]
This works as expected (example from docs):
irb(main):017:0> NetAddr.merge(['192.168.1.0/26', '192.168.1.64/27',
'192.168.1.96/27', '10.1.0.0/26', '10.1.0.64/26'])
=> ["10.1.0.0/25", "192.168.1.0/25"]
This should merge the 192.168.x.x to the /16:
irb(main):019:0* NetAddr.merge(['192.168.1.0/26', '192.168.1.64/27',
'192.168.1.96/27', '10.1.0.0/26', '10.1.0.64/26', '192.168.0.0/16'])
=> ["10.1.0.0/25", "192.168.0.0/16", "192.168.1.0/25"]
Here is the same idea in perl using Net::CIDR::Set:
$ perl -MNet::CIDR::Set -e '$s =
Net::CIDR::Set->new("10.0.0.0/8","10.0.0.0/12"); printf("%s\n",
join("\n", $s->as_cidr_array()))'
10.0.0.0/8
$ perl -MNet::CIDR::Set -e '$s =
Net::CIDR::Set->new("10.0.0.0/8","10.0.0.0/16"); printf("%s\n",
join("\n", $s->as_cidr_array()))'
10.0.0.0/8
$ perl -MNet::CIDR::Set -e '$s = Net::CIDR::Set->new("192.168.1.0/26",
"192.168.1.64/27", "192.168.1.96/27", "10.1.0.0/26", "10.1.0.64/26");
printf("%s\n", join("\n", $s->as_cidr_array()))'
10.1.0.0/25
192.168.1.0/25
$ perl -MNet::CIDR::Set -e '$s = Net::CIDR::Set->new("192.168.1.0/26",
"192.168.1.64/27", "192.168.1.96/27", "10.1.0.0/26", "10.1.0.64/26",
"192.168.0.0/16"); printf("%s\n", join("\n", $s->as_cidr_array()))'
10.1.0.0/25
192.168.0.0/16
Ruby/gem info.
$ ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
danb-laptop$ gem list netaddr
*** LOCAL GEMS ***
netaddr (1.5.0)
Under which license is this code?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.