在Amazon Neptune图数据库中查询IP地址(IPv4/IPv6) [英] Querying IP addresses (IPv4/IPv6) in Amazon Neptune graph database

查看:111
本文介绍了在Amazon Neptune图数据库中查询IP地址(IPv4/IPv6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在Neptune中存储IP地址范围的方法,这将使我以后能够基于IP范围运行查询.
几个例子:
1.查找具有属性"address_range"的所有顶点,其中地址在子网X
中 2.查找具有属性"address_range"的所有顶点,其中地址不在子网Y
中 3.找到地址与子网Z重叠的所有具有"address_range"属性的顶点

I'm looking for a way to store IP address ranges in Neptune which will enable me later on to run queries based on IP ranges.
Few examples:
1. Find all vertexes with property "address_range" where the address is in the subnet X
2. Find all vertexes with property "address_range" where the address is in not in the subnet Y
3. Find all vertexes with property "address_range" where the address overlaps with subnet Z

其中X,Y,Z是诸如62.93.132.186/28之类的子网.
IPv6范围也是如此.

Where X,Y,Z are subnets like 62.93.132.186/28.
The same goes for IPv6 ranges.

  • 我正在使用Gremlin(如果有关系的话)

推荐答案

我认为用gremlin实现此目的的最佳方法是存储子网的整数值:fromIptoIp,然后可以运行简单的查询使用gte&等整数运算符lte回答每种情况:

I think the best way to achieve this with gremlin is to store integers values for your subnets: fromIp and toIp then you can run a simple query with integer operators like gte & lte to answer each case:

由子网X包含:

g.V().hasLabel('Subnet').has('fromIp', gte(X.fromIp)).has('toIp', lte(X.toIp))

不包含在子网Y中:

g.V().hasLabel('Subnet').not(
  has('fromIp', gte(Y.fromIP)).
  has('toIp', lte(Y.toIp)))

与子网Z重叠:

g.V().hasLabel('Subnet').where(coalesce(
     has('fromIp', lte(Z.fromIp)).has('toIp', gte(Z.fromIp)),
     has('fromIp', lte(Z.toIp)).has('toIp', gte(Z.toIp),
))

示例: https://gremlify.com/7g

db中的子网:10.0.0.0/28、10.0.0.0/8、11.0.0.0/8

subnets in db: 10.0.0.0/28, 10.0.0.0/8 , 11.0.0.0/8

测试子网:10.0.0.0/24(167772161,167772414):

test subnet: 10.0.0.0/24(167772161, 167772414):

g.inject(1).
  project('contain', 'not-contain', 'overlap').
    by(V().hasLabel('Subnet').
      has('fromIp', gte(167772161)).
      has('toIp', lte(167772414)).values('subnet').fold()).
    by(V().hasLabel('Subnet').
      not(has('fromIp', gte(167772161)).
        has('toIp', lte(167772414))).values('subnet').fold()).
    by(V().hasLabel('Subnet').coalesce(
        has('fromIp', lte(167772161)).
        has('toIp', gte(167772161)),
        has('fromIp', lte(167772414)).
        has('toIp', gte(167772414))
      ).values('subnet').fold())

这篇关于在Amazon Neptune图数据库中查询IP地址(IPv4/IPv6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆