From 3a3abdd01c8cb0c1591833f5b2987ecb4e17ef39 Mon Sep 17 00:00:00 2001 From: lionsoul2014 Date: Wed, 29 Oct 2025 16:03:19 +0800 Subject: [PATCH] python ipv6 supporting --- binding/python/xdb/__init__.py | 5 ++ binding/python/xdb/util.py | 129 +++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 binding/python/xdb/__init__.py create mode 100644 binding/python/xdb/util.py diff --git a/binding/python/xdb/__init__.py b/binding/python/xdb/__init__.py new file mode 100644 index 0000000..8f9fe4a --- /dev/null +++ b/binding/python/xdb/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2022 The Ip2Region Authors. All rights reserved. +# Use of this source code is governed by a Apache2.0-style +# license that can be found in the LICENSE file. + +# xdb package \ No newline at end of file diff --git a/binding/python/xdb/util.py b/binding/python/xdb/util.py new file mode 100644 index 0000000..f66b600 --- /dev/null +++ b/binding/python/xdb/util.py @@ -0,0 +1,129 @@ +# Copyright 2022 The Ip2Region Authors. All rights reserved. +# Use of this source code is governed by a Apache2.0-style +# license that can be found in the LICENSE file. + +# xdb utils on 2025/10/29 +# Author Leon + +import io +import struct + +# global constants +XdbStructure20 = 2 +XdbStructure30 = 3 +XdbIPv4Id = 4 +XdbIPv6Id = 6 + +HeaderInfoLength = 256 +VectorIndexRows = 256 +VectorIndexCols = 256 +VectorIndexSize = 8 + +class Header(object): + ''' + header class + ''' + def __init__(self, buff): + self.version = struct.unpack_from("", IPv4) + print("IPv6 ->", IPv6) + print("version_from_name(v4) ->", version_from_name("v4")) + print("version_from_name(v6) ->", version_from_name("v4")) + print("version_from_header() ->", version_from_header(header))