https://github.com/robertmassaioli/iprange
A work in progress library to handle IP ranges.
https://github.com/robertmassaioli/iprange
Last synced: about 2 months ago
JSON representation
A work in progress library to handle IP ranges.
- Host: GitHub
- URL: https://github.com/robertmassaioli/iprange
- Owner: robertmassaioli
- Created: 2009-11-10T09:50:56.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2012-08-14T23:28:34.000Z (over 12 years ago)
- Last Synced: 2025-01-23T12:46:08.069Z (4 months ago)
- Language: C++
- Homepage:
- Size: 109 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# iprange
By Robert Massaioli ([email protected])## Purpose
The purpose of this library is to provide a way to add ranges of IP's to an object
and then retrieve wether or not an IP address is in that range. This project is supposed
to be robust and be able to handle bad input in nice ways as well as being easily able to
hande both IPv4 and IPv6 adresses. (NOTE: Currently only IPv4 adresses are supported)## Adding to a project
Currently just make sure that iprange.(tcc|h) are in your include path and say:
#include
Then when you make the class you have to call:
IPRange myRangeObject;
When you want to add ip adresses:
// this one example includes every possible range type you can specify
myRangeObject.add("192.*.[0-10].[100-*]");When you want to check is a single IP address is in and range you have added:
if(myRangeObject.includes("192.168.0.199")) {
cout << "Hey, it's included!" << endl;
} else {
cout << "Dang, it's not." << endl;
}And that's all there is to it.
## Functions Provided
- add | add a new IP range
- includes | is an ip included in any of the ranges
- size | how many ranges does the object have
- clear | remove and free all ranges from the object
- << | output the object to an ostream# Technical Details
The search through the IP adresses is linear; working on making it binary
search in the near future.