在 redshift 中根据 CIDR 范围检查 IP 地址

Checking an IP Address against an CIDR range in redshift

我遇到了一个问题,我一直在努力解决我已经在谷歌上搜索了一些与我想做的事情类似的事情,但无法确切地知道如何去做,

我有大约 250M 个 IP 地址,我想将其与 maxmind geolite2 数据进行比较,以便我可以判断每个 IP 地址来自哪个国家/地区,

我已经使用 talend 将所有数据导入到我的 Redshift 集群中,

table a has ID and 'ipaddress' ie 10.0.0.5
table b (maxmind) has country name and IP range as expressed as 10.0.0.0/24

考虑到我的源数据源的大小,我如何使用 Redshift SQL 来匹配这两个?

编辑:这里是 link 到 geolite2 数据 https://dev.maxmind.com/geoip/geoip2/geolite2/

您可以尝试使用 Amazon Redshift 的功能 Import Custom Python Library Modules to load the netaddr library。然后,您可以在用 Python.

编写的用户定义函数中使用该库

另请参阅:IP Range to CIDR conversion in Python?