[英]receive all matching networks for IP address from postgres db
I have a postgres db with a table networks
which includes a column network
of type cidr.我有一个带有表
networks
的 postgres 数据库,其中包括一个 cidr 类型的列network
。 I want to queue all networks which contain an IP address I provide.我想对包含我提供的 IP 地址的所有网络进行排队。 I couldnt find how to do this.
我找不到如何做到这一点。
Currently I pull all networks, and then use the include?
目前我拉所有网络,然后使用
include?
method IPAddr class provides: IPAddr 类提供的方法:
Network.all.each{|row| pp row if row.network.include?("10.176.0.5")}
您可以使用为 cidr 类型定义的 postgres 的>>=
运算符(包括或等于)或>>
(包括):
Network.where(['network >> ?', "10.176.0.5"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.