Skip to main content

Network utilities for IP address detection and classification

Project description

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

#!/usr/bin/env python

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

k3net-0.1.5.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3net-0.1.5-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file k3net-0.1.5.tar.gz.

File metadata

  • Download URL: k3net-0.1.5.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3net-0.1.5.tar.gz
Algorithm Hash digest
SHA256 41693caf09796e8e90fb5d5b0216c9b6087fb329e39b95dee061849126659c7d
MD5 2c604005a36cd66df803688d18d1d49a
BLAKE2b-256 1a76127a07a11410cb8b20a896d6105b1c0cf632c06435667f40136a07ce380f

See more details on using hashes here.

File details

Details for the file k3net-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: k3net-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3net-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 963f71d492fb4951f3cd264858243c29d40712bbdaac89087f539394b87b6811
MD5 63b10b3a37901a073ba447d62f327a3a
BLAKE2b-256 47de285dfd5278d723fb6fcd6d3245e00c2b3f487541cd4f116fab06df2f68b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page