You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Carl Bourne <ca...@me.com> on 2012/10/19 15:27:53 UTC

Storing and Grouping IP Addresses in Couch

Hi,

I have a Couch Database that contains a stack of IP address documents like this:

{
   "_id": "09eea172ea6537ad0bf58c92e5002199",
   "_rev": "1-67ad27f5ab008ad9644ce8ae003b1ec5",
   "1stOctet": "10",
   "2ndOctet": "60",
   "3rdOctet": "129",
   "4thOctet": "161"
}

The documents consist of multiple IP that are part of different subnet ranges. 

I need a way to reduce/group these documents based on the 1st, 2nd, 3rd and 4th Octets in order to produce a reduced list of subnets.

Has anybody done anything like this before.

Best Regards,

Carl



Re: Storing and Grouping IP Addresses in Couch

Posted by Peter W <li...@pw.de>.
Hi,

Am 19.10.2012 15:27, schrieb Carl Bourne:
> Hi,
> 
> I have a Couch Database that contains a stack of IP address documents like this:
> 
> {
>    "_id": "09eea172ea6537ad0bf58c92e5002199",
>    "_rev": "1-67ad27f5ab008ad9644ce8ae003b1ec5",
>    "1stOctet": "10",
>    "2ndOctet": "60",
>    "3rdOctet": "129",
>    "4thOctet": "161"
> }
> 
> The documents consist of multiple IP that are part of different subnet ranges. 
> 
> I need a way to reduce/group these documents based on the 1st, 2nd, 3rd and 4th Octets in order to produce a reduced list of subnets.
> 
> Has anybody done anything like this before.

some time ago, I played with a proof of conecpt for an IP
presentation/management tool based on couchdb. My first steps:

- Put IP-Networks in CDIR format (e.g. 192.1.2.3/24) into
  a string per document

- map function with following key-format for correct sorting:
  [IP-Version, CDIR, expanded-IP]
  e.g. [4, 24, 192.001.002.003]

client-side I converted IP addresses into bigInt... to be able to
calculate IP addresses/networks. The output was a hierarchical tree of
networks and sub-(sub-)networks.

Best regards,
	Peter.

Re: Storing and Grouping IP Addresses in Couch

Posted by Elisiano Petrini <el...@gmail.com>.
Hi Carl,
    I don't know your use case but bear in mind that an octet could be split in more subnets.
This means that if you want to group by subnets you should be able to extract the CIDR address of the subnet and use it as a key.

Cheers, Elisiano

On Oct 19, 2012, at 4:07 PM, Carl Bourne <ca...@me.com> wrote:

> Matt, 
> 
> Yes I think so. I was hoping to use the group level feature to group based on the 1st, 2nd, 3rd and 4th octets with the IP address, thus providing a list of the different subnets. 
> 
> Carl Bourne | Senior Sales Engineer | mobile: +44 (0) 7770 284294 | www.venafi.com
> 
> On 19 Oct 2012, at 14:56, "matt j. sorenson" <ma...@sorensonbros.net> wrote:
> 
>> On Fri, Oct 19, 2012 at 8:27 AM, Carl Bourne <ca...@me.com> wrote:
>> 
>>> Hi,
>>> 
>>> I have a Couch Database that contains a stack of IP address documents like
>>> this:
>>> 
>>> {
>>>  "_id": "09eea172ea6537ad0bf58c92e5002199",
>>>  "_rev": "1-67ad27f5ab008ad9644ce8ae003b1ec5",
>>>  "1stOctet": "10",
>>>  "2ndOctet": "60",
>>>  "3rdOctet": "129",
>>>  "4thOctet": "161"
>>> }
>>> 
>>> The documents consist of multiple IP that are part of different subnet
>>> ranges.
>>> 
>>> I need a way to reduce/group these documents based on the 1st, 2nd, 3rd
>>> and 4th Octets in order to produce a reduced list of subnets.
>>> 
>>> Has anybody done anything like this before.
>>> 
>>> Best Regards,
>>> 
>>> Carl
>> 
>> like this?
>> http://chesterfield.iriscouch.com/samples/_design/samples/_view/ipaddresses?group=true
>> 
>> note that it may be ill-advised to use keys that begin w/a numeric, like
>> 1stOctet... might be safer to use e.g. "octet1" "octet2" etc... just
>> thinking out loud.
>> 
>> --
>> *matt j. sorenson*


Re: Storing and Grouping IP Addresses in Couch

Posted by Carl Bourne <ca...@me.com>.
Matt, 

Yes I think so. I was hoping to use the group level feature to group based on the 1st, 2nd, 3rd and 4th octets with the IP address, thus providing a list of the different subnets. 

Carl Bourne | Senior Sales Engineer | mobile: +44 (0) 7770 284294 | www.venafi.com

On 19 Oct 2012, at 14:56, "matt j. sorenson" <ma...@sorensonbros.net> wrote:

> On Fri, Oct 19, 2012 at 8:27 AM, Carl Bourne <ca...@me.com> wrote:
> 
>> Hi,
>> 
>> I have a Couch Database that contains a stack of IP address documents like
>> this:
>> 
>> {
>>   "_id": "09eea172ea6537ad0bf58c92e5002199",
>>   "_rev": "1-67ad27f5ab008ad9644ce8ae003b1ec5",
>>   "1stOctet": "10",
>>   "2ndOctet": "60",
>>   "3rdOctet": "129",
>>   "4thOctet": "161"
>> }
>> 
>> The documents consist of multiple IP that are part of different subnet
>> ranges.
>> 
>> I need a way to reduce/group these documents based on the 1st, 2nd, 3rd
>> and 4th Octets in order to produce a reduced list of subnets.
>> 
>> Has anybody done anything like this before.
>> 
>> Best Regards,
>> 
>> Carl
> 
> like this?
> http://chesterfield.iriscouch.com/samples/_design/samples/_view/ipaddresses?group=true
> 
> note that it may be ill-advised to use keys that begin w/a numeric, like
> 1stOctet... might be safer to use e.g. "octet1" "octet2" etc... just
> thinking out loud.
> 
> --
> *matt j. sorenson*

Re: Storing and Grouping IP Addresses in Couch

Posted by "matt j. sorenson" <ma...@sorensonbros.net>.
On Fri, Oct 19, 2012 at 8:27 AM, Carl Bourne <ca...@me.com> wrote:

> Hi,
>
> I have a Couch Database that contains a stack of IP address documents like
> this:
>
> {
>    "_id": "09eea172ea6537ad0bf58c92e5002199",
>    "_rev": "1-67ad27f5ab008ad9644ce8ae003b1ec5",
>    "1stOctet": "10",
>    "2ndOctet": "60",
>    "3rdOctet": "129",
>    "4thOctet": "161"
> }
>
> The documents consist of multiple IP that are part of different subnet
> ranges.
>
> I need a way to reduce/group these documents based on the 1st, 2nd, 3rd
> and 4th Octets in order to produce a reduced list of subnets.
>
> Has anybody done anything like this before.
>
> Best Regards,
>
> Carl
>

like this?
http://chesterfield.iriscouch.com/samples/_design/samples/_view/ipaddresses?group=true

note that it may be ill-advised to use keys that begin w/a numeric, like
1stOctet... might be safer to use e.g. "octet1" "octet2" etc... just
thinking out loud.

--
*matt j. sorenson*