algorithm - 如果 IP 在范围列表中,则过滤它们
问题描述
在 Kusto,我正在努力解决算法问题。我得到了 IP 的大列表(Azure Monitor),以及要列入白名单的范围列表。如果 IP 在第二个列表的范围内,我如何排除第一个列表的行?
当然我们会使用ipv4_is_in_range()
andmv-apply
为此,但我不知道如何。
样品项目:
let ranges_to_whitelist = "['127.0.0.1', 10.0.0.0/28']";
let big_table_of_rows = datatable (ip_range: string) ['1.2.3.4', '10.0.0.254', '172.16.1.2', '10.0.0.1'];
应该产生:
datatable (ip_range: string) ['10.0.0.1'];
谢谢!
解决方案
如果我正确理解了要求,您需要首先将范围数组扩展为白名单(使用mv-expand
or mv-apply
),然后根据以下条件应用过滤器ipv4_is_in_range()
:
let ranges_to_whitelist = dynamic(['127.0.0.1', '10.0.0.0/28']);
let big_table_of_rows = datatable (ip: string) ['1.2.3.4', '10.0.0.254', '172.16.1.2', '10.0.0.1'];
big_table_of_rows
| mv-apply ip_range = ranges_to_whitelist to typeof(string) on (
where ipv4_is_in_range(ip, ip_range)
)
| project-away ip_range
ip |
---|
10.0.0.1 |
或者,对于相反的情况:
let ranges_to_whitelist = dynamic(['127.0.0.1', '10.0.0.0/28']);
let big_table_of_rows = datatable (ip: string) ['1.2.3.4', '10.0.0.254', '172.16.1.2', '10.0.0.1'];
big_table_of_rows
| mv-apply ip_range = ranges_to_whitelist to typeof(string) on (
summarize countif(ipv4_is_in_range(ip, ip_range))
| where countif_ == 0
)
| project-away countif_
ip |
---|
1.2.3.4 |
10.0.0.254 |
172.16.1.2 |
推荐阅读
- javascript - 如何在 Webpack 4 中转译 JSX
- python - 如果我在加载 DLL 后使用 np.log10,Python 内核会崩溃
- android - 如何使用 React Native 在 Android 上允许自签名证书
- java - GraphView 不显示折线图
- javascript - Tampermonkey Userscript 可以访问 Chrome API 吗?
- apache-spark - 创建 One-Hot 编码器。CountVectorizer 使用 ArrayType(IntergerType, true) 返回错误
- vue.js - vuetify `v-tabs` 的子组件将 offsetWidth 返回为 0
- ruby-on-rails - 如何禁用 Active Storage 自动生成的路由
- bash - OpenSSL 解密 AES 256 位(base64)加密密码 - 最终块长度错误
- node.js - 如何使用 Express 和 Node 创建一个简单的用户配置文件 URL?