Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/abates/ip_tools

This project adds a number of useful method to Ruby's IpAddr class. It also creates a validator that can validate strings in IPv4 or IPv6 format
https://github.com/abates/ip_tools

Last synced: about 7 hours ago
JSON representation

This project adds a number of useful method to Ruby's IpAddr class. It also creates a validator that can validate strings in IPv4 or IPv6 format

Awesome Lists containing this project

README

        

IpTools
=======

IpTools is a Ruby on Rails plugin that provides some useful functionality to the IpAddr class that ships with Ruby.

This plugin creates methods that will return the netmask of an IpAddr object, as well as its prefix (used in CIDR notation), as well as methods to retrieve the inverse mask and broadcast. These methods simplify working with IpAddr objects, especially when binary arithmetic is required to find IPs within ranges, etc.

Example
=======

require "ipaddr"
require "netmask_tools"

ip = IPAddr.new("192.168.1.0/24", Socket::AF_INET)

print "#{ip.netmask}\n" # 255.255.255.0
print "#{ip.broadcast}\n" # 192.168.1.255
print "#{ip.prefix}\n" # 24

Copyright (c) 2010 Andrew Bates, released under the MIT license