Skip to main content

k3net

Action-CI Documentation Status Package

Utility functions for network related operation.

k3net is a component of pykit3 project: a python3 toolkit set.

Install

pip install k3net

Synopsis

import k3net

if __name__ == "__main__":
    # Check if an IP is valid IPv4
    print(k3net.is_ip4("192.168.0.1"))  # True
    print(k3net.is_ip4("invalid"))  # False

    # Check if IP is public or private (INN)
    print(k3net.is_pub("1.2.3.4"))  # True
    print(k3net.is_inn("192.168.0.1"))  # True

    # Get IP class
    print(k3net.ip_class("1.2.3.4"))  # PUB
    print(k3net.ip_class("192.168.0.1"))  # INN

    # Select IPs by class
    ips = ["1.2.3.4", "192.168.0.1", "10.0.0.1"]
    print(k3net.choose_pub(ips))  # ['1.2.3.4']
    print(k3net.choose_inn(ips))  # ['192.168.0.1', '10.0.0.1']

    # Prefer public or private IPs
    print(k3net.ips_prefer(ips, k3net.PUB))  # Public IPs first
    print(k3net.ips_prefer(ips, k3net.INN))  # Private IPs first

    # Get host IP addresses
    host_ips = k3net.get_host_ip4()
    print(host_ips)  # List of host IPv4 addresses

    # IP to number conversion
    num = k3net.ip_to_num("192.168.0.1")
    print(num)  # 3232235521
    print(k3net.num_to_ip(num))  # '192.168.0.1'

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3net 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3net 0.1.8
File Size Uploaded
k3net-0.1.8.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3net 0.1.8
File Interpreter ABI Platform
k3net-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / k3net-0.1.8.tar.gz

Download URL k3net-0.1.8.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
de33ac2622a68762aec544014c3c3711718e8eb060f5f36334d3444141af9354
BLAKE2b-256 checksum
How to use checksums
770e2c476ede78f41cc0fb87f45f1823a74ee26dbd0945de5549eb149b947cd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3net-0.1.8-py3-none-any.whl

Download URL k3net-0.1.8-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b93e9c40626873ee56b1c8fcc1540701649e529ae81d8c28fe52e18307a0992
BLAKE2b-256 checksum
How to use checksums
5d2bde42545881ff332a413fe21d3dfb532eb7c080caf219e7f8cab6b74f5d6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.1.9

2 release files

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page