Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gromnitsky/cidr.rb

an IPv4 CIDR blocks renderer w/ an offline CIDR/VLSM calculator
https://github.com/gromnitsky/cidr.rb

Last synced: about 6 hours ago
JSON representation

an IPv4 CIDR blocks renderer w/ an offline CIDR/VLSM calculator

Awesome Lists containing this project

README

        

# cidr.rb

Renders IPv4 CIDR blocks in console or browser. The latter is suitable
for printing & pinning it to the wall.

Includes a simple CIDR/VLSM calculator. Works offline (except for geo
ip lookups).

Example: http://gromnitsky.users.sourceforge.net/js/cidr.rb/#/?q=128.42.5.17+%7E+128.42.5.18

## Usage

~~~
$ ruby cidr.rb
~~~
or

~~~
$ ruby cidr.rb html > index.html
$ xdg-open !$
~~~

## Library

$ npm i cidr.rb

Address manipulations:

~~~
> cidr = require('cidr.rb')
>
> new cidr.IPv4(256)
#
> new cidr.IPv4('1.2.3.4')
#
> a = new cidr.IPv4('1.2.3.4') + 1
16909061
> new cidr.IPv4(a + 10)
#
> new cidr.IPv4('1.2.3.4') < new cidr.IPv4('1.2.3.5')
true
> new cidr.IPv4('1.2.3.4').eq(new cidr.IPv4('1.2.3.4'))
true
> new cidr.IPv4('1.2.3.4').eq('1.2.3.4')
true
> new cidr.IPv4('1.2.3.4').reverse()
'4.3.2.1.in-addr.arpa'
> new cidr.IPv4('1.2.3.4').to_a()
[ [ 0, 0, 0, 0, 0, 0, 0, 1 ],
[ 0, 0, 0, 0, 0, 0, 1, 0 ],
[ 0, 0, 0, 0, 0, 0, 1, 1 ],
[ 0, 0, 0, 0, 0, 1, 0, 0 ] ]
~~~

Network:

~~~
> new cidr.Net('1.2.3.4/16')
#
> new cidr.Net('1.2.3.4', 16)
#
> new cidr.Net(new cidr.IPv4('1.2.3.4'), new cidr.IPv4('255.255.0.0'))
#
> a = new cidr.Net('1.2.3.4/16')
#
> a.eq('1.2.3.4/16')
true
> a.eq(new cidr.Net('1.2.3.4/16'))
true
> a.netaddr()
#
> a.hostaddr()
#
> a.broadcast()
#
> a.range()
[ #, # ]
> Array.from(new cidr.Net('1.2.3.4/29').to_iter())
[ #,
#,
#,
#,
#,
# ]
> new cidr.Net('192.168.1.1/24').describe()
{ type: 'Special-purpose',
subtype: 'Private-Use, attrs=SDF',
link: '192.168.0.0/16' }
> new cidr.Net('192.168.1.1/24').maxhosts()
254
> new cidr.Net('192.168.1.1/28').includes('192.168.1.10')
true
> new cidr.Net('192.168.1.1/28').includes('192.168.1.40')
false
> cidr.Net.Cidr_max(new cidr.IPv4('128.42.5.17'), new cidr.IPv4('128.42.5.18'))
30
> new cidr.Net('192.168.1.0/26').vlsm([1,7,29,2,6])
{ error: null,
tbl:
[ { nhosts: 29, net: # },
{ nhosts: 7, net: # },
{ nhosts: 6, net: # },
{ nhosts: 2, net: # },
{ nhosts: 1, net: # } ] }
> new cidr.Net('192.0.2.1/32') < new cidr.Net('192.0.2.2/32')
true
~~~

## Bugs

* Chrome 53+, Firefox 50+ only (No Edge or Safari support).
* IPv4 only. I don't like all this 'new' IPv6 staff. I hope IPv6 fad
will end someday! hehe

## License

MIT.