Clickhouse IP 函数
IPv4NumToString(num)
将数字类型ip转换为IPv4格式。
Takes a UInt32 number. Interprets it as an IPv4 address in big endian. Returns a string containing the corresponding IPv4 address in the format A.B.C.d (dot-separated numbers in decimal form).
Alias: INET_NTOA.
IPv4StringToNum(s)
将IPv4转换为数字。
The reverse function of IPv4NumToString. If the IPv4 address has an invalid format, it throws exception.
Alias: INET_ATON.
IPv4StringToNumOrDefault(s)
Same as IPv4StringToNum, but if the IPv4 address has an invalid format, it returns 0.
IPv4StringToNumOrNull(s)
Same as IPv4StringToNum, but if the IPv4 address has an invalid format, it returns null.
IPv4NumToStringClassC(num)
Similar to IPv4NumToString, but using xxx instead of the last octet.
Example:
SELECTIPv4NumToStringClassC(ClientIP) AS k,count() AS c
FROM test.hits
GROUP BY k
ORDER BY c DESC
LIMIT 10
┌─k──────────────┬─────c─┐
│ 83.149.9.xxx │ 26238 │
│ 217.118.81.xxx │ 26074 │
│ 213.87.129.xxx │ 25481 │
│ 83.149.8.xxx │ 24984 │
│ 217.118.83.xxx │ 22797 │
│ 78.25.120.xxx │ 22354 │
│ 213.87.131.xxx │ 21285 │
│ 78.25.121.xxx │ 20887 │
│ 188.162.65.xxx │ 19694 │
│ 83.149.48.xxx │ 17406 │
└────────────────┴───────┘
Since using ‘xxx’ is highly unusual, this may be changed in the future. We recommend that you do not rely on the exact format of this fragment.
IPv6NumToString(x)
Accepts a FixedString(16) value containing the IPv6 address in binary format. Returns a string containing this address in text format. IPv6-mapped IPv4 addresses are output in the format ::ffff:111.222.33.44.
Alias: INET6_NTOA.
Examples:
SELECT IPv6NumToString(toFixedString(unhex('2A0206B8000000000000000000000011'), 16)) AS addr;
┌─addr─────────┐
│ 2a02:6b8::11 │
└──────────────┘
SELECTIPv6NumToString(ClientIP6 AS k),count() AS c
FROM hits_all
WHERE EventDate = today() AND substring(ClientIP6, 1, 12) != unhex('00000000000000000000FFFF')
GROUP BY k
ORDER BY c DESC
LIMIT 10
┌─IPv6NumToString(ClientIP6)──────────────┬─────c─┐
│ 2a02:2168:aaa:bbbb::2 │ 24695 │
│ 2a02:2698:abcd:abcd:abcd:abcd:8888:5555 │ 22408 │
│ 2a02:6b8:0:fff::ff │ 16389 │
│ 2a01:4f8:111:6666::2 │ 16016 │
│ 2a02:2168:888:222::1 │ 15896 │
│ 2a01:7e00::ffff:ffff:ffff:222 │ 14774 │
│ 2a02:8109:eee:ee:eeee:eeee:eeee:eeee │ 14443 │
│ 2a02:810b:8888:888:8888:8888:8888:8888 │ 14345 │
│ 2a02:6b8:0:444:4444:4444:4444:4444 │ 14279 │
│ 2a01:7e00::ffff:ffff:ffff:ffff │ 13880 │
└─────────────────────────────────────────┴───────┘
SELECTIPv6NumToString(ClientIP6 AS k),count() AS c
FROM hits_all
WHERE EventDate = today()
GROUP BY k
ORDER BY c DESC
LIMIT 10
┌─IPv6NumToString(ClientIP6)─┬──────c─┐
│ ::ffff:94.26.111.111 │ 747440 │
│ ::ffff:37.143.222.4 │ 529483 │
│ ::ffff:5.166.111.99 │ 317707 │
│ ::ffff:46.38.11.77 │ 263086 │
│ ::ffff:79.105.111.111 │ 186611 │
│ ::ffff:93.92.111.88 │ 176773 │
│ ::ffff:84.53.111.33 │ 158709 │
│ ::ffff:217.118.11.22 │ 154004 │
│ ::ffff:217.118.11.33 │ 148449 │
│ ::ffff:217.118.11.44 │ 148243 │
└────────────────────────────┴────────┘
IPv6StringToNum
The reverse function of IPv6NumToString. If the IPv6 address has an invalid format, it throws exception.
If the input string contains a valid IPv4 address, returns its IPv6 equivalent. HEX can be uppercase or lowercase.
Alias: INET6_ATON.
Syntax
IPv6StringToNum(string)
Argument
string— IP address. String.
Returned value
- IPv6 address in binary format.
Type: FixedString(16).
Example
Query:
SELECT addr, cutIPv6(IPv6StringToNum(addr), 0, 0) FROM (SELECT ['notaddress', '127.0.0.1', '1111::ffff'] AS addr) ARRAY JOIN addr;
Result:
┌─addr───────┬─cutIPv6(IPv6StringToNum(addr), 0, 0)─┐
│ notaddress │ :: │
│ 127.0.0.1 │ ::ffff:127.0.0.1 │
│ 1111::ffff │ 1111::ffff │
└────────────┴──────────────────────────────────────┘
See Also
- cutIPv6.
IPv6StringToNumOrDefault(s)
Same as IPv6StringToNum, but if the IPv6 address has an invalid format, it returns 0.
IPv6StringToNumOrNull(s)
Same as IPv6StringToNum, but if the IPv6 address has an invalid format, it returns null.
IPv4ToIPv6(x)
Takes a UInt32 number. Interprets it as an IPv4 address in big endian. Returns a FixedString(16) value containing the IPv6 address in binary format. Examples:
SELECT IPv6NumToString(IPv4ToIPv6(IPv4StringToNum('192.168.0.1'))) AS addr;
┌─addr───────────────┐
│ ::ffff:192.168.0.1 │
└────────────────────┘
cutIPv6(x, bytesToCutForIPv6, bytesToCutForIPv4)
Accepts a FixedString(16) value containing the IPv6 address in binary format. Returns a string containing the address of the specified number of bytes removed in text format. For example:
WITHIPv6StringToNum('2001:0DB8:AC10:FE01:FEED:BABE:CAFE:F00D') AS ipv6,IPv4ToIPv6(IPv4StringToNum('192.168.0.1')) AS ipv4
SELECTcutIPv6(ipv6, 2, 0),cutIPv6(ipv4, 0, 2)
┌─cutIPv6(ipv6, 2, 0)─────────────────┬─cutIPv6(ipv4, 0, 2)─┐
│ 2001:db8:ac10:fe01:feed:babe:cafe:0 │ ::ffff:192.168.0.0 │
└─────────────────────────────────────┴─────────────────────┘
IPv4CIDRToRange(ipv4, Cidr),
Accepts an IPv4 and an UInt8 value containing the CIDR. Return a tuple with two IPv4 containing the lower range and the higher range of the subnet.
SELECT IPv4CIDRToRange(toIPv4('192.168.5.2'), 16);
┌─IPv4CIDRToRange(toIPv4('192.168.5.2'), 16)─┐
│ ('192.168.0.0','192.168.255.255') │
└────────────────────────────────────────────┘
IPv6CIDRToRange(ipv6, Cidr),
Accepts an IPv6 and an UInt8 value containing the CIDR. Return a tuple with two IPv6 containing the lower range and the higher range of the subnet.
SELECT IPv6CIDRToRange(toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 32);
┌─IPv6CIDRToRange(toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 32)─┐
│ ('2001:db8::','2001:db8:ffff:ffff:ffff:ffff:ffff:ffff') │
└────────────────────────────────────────────────────────────────────────┘
toIPv4(string)
An alias to IPv4StringToNum() that takes a string form of IPv4 address and returns value of IPv4 type, which is binary equal to value returned by IPv4StringToNum().
WITH'171.225.130.45' as IPv4_string
SELECTtoTypeName(IPv4StringToNum(IPv4_string)),toTypeName(toIPv4(IPv4_string))
┌─toTypeName(IPv4StringToNum(IPv4_string))─┬─toTypeName(toIPv4(IPv4_string))─┐
│ UInt32 │ IPv4 │
└──────────────────────────────────────────┴─────────────────────────────────┘
WITH'171.225.130.45' as IPv4_string
SELECThex(IPv4StringToNum(IPv4_string)),hex(toIPv4(IPv4_string))
┌─hex(IPv4StringToNum(IPv4_string))─┬─hex(toIPv4(IPv4_string))─┐
│ ABE1822D │ ABE1822D │
└───────────────────────────────────┴──────────────────────────┘
toIPv4OrDefault(string)
Same as toIPv4, but if the IPv4 address has an invalid format, it returns 0.0.0.0 (0 IPv4).
toIPv4OrNull(string)
Same as toIPv4, but if the IPv4 address has an invalid format, it returns null.
toIPv6OrDefault(string)
Same as toIPv6, but if the IPv6 address has an invalid format, it returns :: (0 IPv6).
toIPv6OrNull(string)
Same as toIPv6, but if the IPv6 address has an invalid format, it returns null.
toIPv6
Converts a string form of IPv6 address to IPv6 type. If the IPv6 address has an invalid format, returns an empty value. Similar to IPv6StringToNum function, which converts IPv6 address to binary format.
If the input string contains a valid IPv4 address, then the IPv6 equivalent of the IPv4 address is returned.
Syntax
toIPv6(string)
Argument
string— IP address. String
Returned value
- IP address.
Type: IPv6.
Examples
Query:
WITH '2001:438:ffff::407d:1bc1' AS IPv6_string
SELECThex(IPv6StringToNum(IPv6_string)),hex(toIPv6(IPv6_string));
Result:
┌─hex(IPv6StringToNum(IPv6_string))─┬─hex(toIPv6(IPv6_string))─────────┐
│ 20010438FFFF000000000000407D1BC1 │ 20010438FFFF000000000000407D1BC1 │
└───────────────────────────────────┴──────────────────────────────────┘
Query:
SELECT toIPv6('127.0.0.1');
Result:
┌─toIPv6('127.0.0.1')─┐
│ ::ffff:127.0.0.1 │
└─────────────────────┘
IPv6StringToNumOrDefault(s)
Same as toIPv6, but if the IPv6 address has an invalid format, it returns 0.
IPv6StringToNumOrNull(s)
Same as toIPv6, but if the IPv6 address has an invalid format, it returns null.
isIPv4String
Determines whether the input string is an IPv4 address or not. If string is IPv6 address returns 0.
Syntax
isIPv4String(string)
Arguments
string— IP address. String.
Returned value
1ifstringis IPv4 address,0otherwise.
Type: UInt8.
Examples
Query:
SELECT addr, isIPv4String(addr) FROM ( SELECT ['0.0.0.0', '127.0.0.1', '::ffff:127.0.0.1'] AS addr ) ARRAY JOIN addr;
Result:
┌─addr─────────────┬─isIPv4String(addr)─┐
│ 0.0.0.0 │ 1 │
│ 127.0.0.1 │ 1 │
│ ::ffff:127.0.0.1 │ 0 │
└──────────────────┴────────────────────┘
isIPv6String
Determines whether the input string is an IPv6 address or not. If string is IPv4 address returns 0.
Syntax
isIPv6String(string)
Arguments
string— IP address. String.
Returned value
1ifstringis IPv6 address,0otherwise.
Type: UInt8.
Examples
Query:
SELECT addr, isIPv6String(addr) FROM ( SELECT ['::', '1111::ffff', '::ffff:127.0.0.1', '127.0.0.1'] AS addr ) ARRAY JOIN addr;
Result:
┌─addr─────────────┬─isIPv6String(addr)─┐
│ :: │ 1 │
│ 1111::ffff │ 1 │
│ ::ffff:127.0.0.1 │ 1 │
│ 127.0.0.1 │ 0 │
└──────────────────┴────────────────────┘
isIPAddressInRange
Determines if an IP address is contained in a network represented in the CIDR notation. Returns 1 if true, or 0 otherwise.
Syntax
isIPAddressInRange(address, prefix)
This function accepts both IPv4 and IPv6 addresses (and networks) represented as strings. It returns 0 if the IP version of the address and the CIDR don't match.
Arguments
address— An IPv4 or IPv6 address. String.prefix— An IPv4 or IPv6 network prefix in CIDR. String.
Returned value
1or0.
Type: UInt8.
Example
Query:
SELECT isIPAddressInRange('127.0.0.1', '127.0.0.0/8');
Result:
┌─isIPAddressInRange('127.0.0.1', '127.0.0.0/8')─┐
│ 1 │
└────────────────────────────────────────────────┘
Query:
SELECT isIPAddressInRange('127.0.0.1', 'ffff::/16');
Result:
┌─isIPAddressInRange('127.0.0.1', 'ffff::/16')─┐
│ 0 │
└──────────────────────────────────────────────┘
Query:
SELECT isIPAddressInRange('::ffff:192.168.0.1', '::ffff:192.168.0.4/128');
Result:
┌─isIPAddressInRange('::ffff:192.168.0.1', '::ffff:192.168.0.4/128')─┐
│ 0 │
└────────────────────────────────────────────────────────────────────┘
相关文章:
Clickhouse IP 函数
IPv4NumToString(num) 将数字类型ip转换为IPv4格式。 Takes a UInt32 number. Interprets it as an IPv4 address in big endian. Returns a string containing the corresponding IPv4 address in the format A.B.C.d (dot-separated numbers in decimal form). Alias: …...
【Python】numpy.ptp()
numpy.ptp() 函数是 NumPy 库中的一个有用函数,用于计算数组中的“峰到峰”(peak-to-peak)值,即数组中的最大值与最小值之差。这个函数可以帮助快速评估数组中数据的变化范围,常用于信号处理、数据分析等领域中&#x…...
The provided password or token is incorrect or your account
IDEA使用git技巧 【/n】 01 问题出现场景 我的gitlab上个月生成的token到期了,于是今天推上去的时候报了这个错误 The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See ht…...
常见的shell命令
以下是一些常见的shell命令: cd:改变当前目录;ls:列出目录中的文件和子目录;mkdir:创建一个新的目录;touch:创建一个新的空文件或更新已存在的文件的时间戳;rmÿ…...
堆栈打印跟踪Activity的启动过程(基于Android10.0.0-r41),framework修改,去除第三方app的倒计时页面
文章目录 堆栈打印跟踪Activity的启动过程(基于Android10.0.0-r41),framework修改,去除第三方app的倒计时页面1.打印异常堆栈2.去除第三方app的倒计时页面3.模拟点击事件跳过首页进入主页 堆栈打印跟踪Activity的启动过程(基于Android10.0.0-r41)&#x…...
只允许内网访问时,如何设置hosts
1、Hosts文件简介 hosts文件是一个没有扩展名的计算机文件,用于将主机名与对应的 IP 地址关联起来。在操作系统中,hosts文件通常用于在本地解析域名,以便将域名映射到特定的IP地址。这个文件可以用来屏蔽广告、加速访问特定网站、解决DNS解析…...
nature《自然》期刊文献怎么在家查看下载
nature《自然》期刊我们都知道,是世界上历史悠久的、最有名望的科学杂志之一。下载该期刊文献是需要使用权限的,如果你没有nature《自然》期刊的资源,又该如何获取呢?请看本文的经验分享。 一、先百度“文献党下载器” 在文献党下…...
python作业五
题目:注册登录 制作一个注册登录模块 注册:将用户填入的账户和密码保存到一个文件(users.bin) 登陆:将用户填入账户密码和users.bin中保存的账户密码进行比对,如果账户和密码完全相同 那 么登录成功,否则登录失败…...
经典的设计模式和Python示例(一)
目录 一、工厂模式(Factory Pattern) 二、单例模式(Singleton Pattern) 三、观察者模式(Observer Pattern) 一、工厂模式(Factory Pattern) 工厂模式(Factory Pattern…...
Ubuntu服务器如何安装桌面
更新软件库 apt-get update 升级软件 apt-get upgrade 安装ubuntu桌面系统 apt-get install ubuntu-desktop 运行过程需要手动确认两次,选择 Y。 安装完成之后,终端输入 reboot,重启服务器。...
填报表如何实现电话号码的校验
单元格校验时,只能输入数字和特定字符(-),即实现固话和手机号码的校验,保证录入的规范,应如何实现? 解决方案:使用正则表达式实现校验效果,如下图所示: 校验…...
揭秘全网热门话题:抖音快速涨粉方法,巨量千川投流助你日增10000粉
在当今社交媒体的时代( 千川投流:hzzxar)抖音成为了年轻人分享自己才华和生活的平台。然而,要在抖音上快速获得关注和粉丝,却不是一件容易的事情。今天,我们将揭秘全网都在搜索的抖音快速涨1000粉的秘籍,带…...
电脑提示‘找不到msvcr110dll,无法继续执行代码’的解决方法,3分钟快速修复
不知道大家有没有遇到过这种情况,无端端电脑提示你找不到msvcr110dll,无法继续执行代码?当出现这个情况,证明你的某个程序就已经运行不了,你需要去修复这个错误,才能正常的运行程序,下面我们一起来详细的了…...
如何在Hostease的Linux虚拟主机上永久移除WordPress网站
最近有遇到客户咨询如何移除Linux虚拟主机上的WordPress网站的, 因为原先的站点长时间不更新,被恶意篡改,跳转到了一个博彩网站上,本身网站也比较旧了,客户也不准备修复,准备重新建站。但是又怕移除不干净&…...
【云原生】Docker 的网络通信
Docker 的网络通信 1.Docker 容器网络通信的基本原理1.1 查看 Docker 容器网络1.2 宿主机与 Docker 容器建立网络通信的过程 2.使用命令查看 Docker 的网络配置信息3.Docker 的 4 种网络通信模式3.1 bridge 模式3.2 host 模式3.3 container 模式3.4 none 模式 4.容器间的通信4.…...
如何优雅的实现浏览器多标签通讯
前言 开发过程中无法避免遇到需要进行多标签通讯的情况,例如: 管理员登陆后,其他打开标签的页面登陆状态要变更课堂页面只能打开一个,另一个则通知失效等等。。。场景 然而实现该功能,我们需要使用页面能共同持有的…...
刷题之不相同的字符串(卡码网模拟)
卡码网不同的字符串 #include<vector> #include<string> #include<iostream> using namespace std; int main() {int n0;cin>>n;for(int i0;i<n;i){string s;cin>>s;vector<int>hash(26,0);for(int j 0;j < s.size();j)hash[s[j…...
JS-导入导出
export和export default是ES6中导出模块中变量的语法 导入导出变量 //导出方法(js文件中) export const 变量名值//导入方法 对应导入的变量,一定要加花括号 import {变量名} from js文件路径 导入导出函数 //导出方法(js文件中…...
【代码随想录——数组篇】
代码随想录——数组篇 2. 二分查找3. 移除元素4. 有序数组的平方5. 长度最小的子数组6. 螺旋矩阵II 2. 二分查找 力扣题目链接 前提: 有序数组数组中无重复元素 代码: (版本一)左闭右闭区间 class Solution {public int sea…...
使用 js 类封装项目中音频播放功能的工具方法utils
在前端开发中,音频播放功能是一个常见的需求,我们经常需要在项目中加入音频播放、音频提示等功能。为了提高开发效率和代码复用性,我们可以封装一个工具方法来管理音频播放功能。 在本文中,我将介绍如何封装项目中音频播放功能的…...
树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法
树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源: http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作,无需更改相机配置。但是,一…...
安宝特方案丨XRSOP人员作业标准化管理平台:AR智慧点检验收套件
在选煤厂、化工厂、钢铁厂等过程生产型企业,其生产设备的运行效率和非计划停机对工业制造效益有较大影响。 随着企业自动化和智能化建设的推进,需提前预防假检、错检、漏检,推动智慧生产运维系统数据的流动和现场赋能应用。同时,…...
vscode(仍待补充)
写于2025 6.9 主包将加入vscode这个更权威的圈子 vscode的基本使用 侧边栏 vscode还能连接ssh? debug时使用的launch文件 1.task.json {"tasks": [{"type": "cppbuild","label": "C/C: gcc.exe 生成活动文件"…...
自然语言处理——循环神经网络
自然语言处理——循环神经网络 循环神经网络应用到基于机器学习的自然语言处理任务序列到类别同步的序列到序列模式异步的序列到序列模式 参数学习和长程依赖问题基于门控的循环神经网络门控循环单元(GRU)长短期记忆神经网络(LSTM)…...
OPenCV CUDA模块图像处理-----对图像执行 均值漂移滤波(Mean Shift Filtering)函数meanShiftFiltering()
操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C11 算法描述 在 GPU 上对图像执行 均值漂移滤波(Mean Shift Filtering),用于图像分割或平滑处理。 该函数将输入图像中的…...
2023赣州旅游投资集团
单选题 1.“不登高山,不知天之高也;不临深溪,不知地之厚也。”这句话说明_____。 A、人的意识具有创造性 B、人的认识是独立于实践之外的 C、实践在认识过程中具有决定作用 D、人的一切知识都是从直接经验中获得的 参考答案: C 本题解…...
Python+ZeroMQ实战:智能车辆状态监控与模拟模式自动切换
目录 关键点 技术实现1 技术实现2 摘要: 本文将介绍如何利用Python和ZeroMQ消息队列构建一个智能车辆状态监控系统。系统能够根据时间策略自动切换驾驶模式(自动驾驶、人工驾驶、远程驾驶、主动安全),并通过实时消息推送更新车…...
uniapp 字符包含的相关方法
在uniapp中,如果你想检查一个字符串是否包含另一个子字符串,你可以使用JavaScript中的includes()方法或者indexOf()方法。这两种方法都可以达到目的,但它们在处理方式和返回值上有所不同。 使用includes()方法 includes()方法用于判断一个字…...
LangFlow技术架构分析
🔧 LangFlow 的可视化技术栈 前端节点编辑器 底层框架:基于 (一个现代化的 React 节点绘图库) 功能: 拖拽式构建 LangGraph 状态机 实时连线定义节点依赖关系 可视化调试循环和分支逻辑 与 LangGraph 的深…...
十九、【用户管理与权限 - 篇一】后端基础:用户列表与角色模型的初步构建
【用户管理与权限 - 篇一】后端基础:用户列表与角色模型的初步构建 前言准备工作第一部分:回顾 Django 内置的 `User` 模型第二部分:设计并创建 `Role` 和 `UserProfile` 模型第三部分:创建 Serializers第四部分:创建 ViewSets第五部分:注册 API 路由第六部分:后端初步测…...
