Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Linux network configuration library for Python
Python
branch: master

Bugfix: current code computes the wrong netmask on some architectures.

See example below, it prints all possible netmasks with the current code
and fixed code. For network masks like 0xffffffe0, math.log(netmask, 2)
returns 4.99999999 on some architectures, which rounded gives 4, which
in turn leads to a netmask of 28 instead of the correct 27.

See the repeated 31 and 28 in the netmasks below.

    >>> import math
    >>> import ctypes
    >>> [32 - int(math.log(ctypes.c_uint32(~(0xffffffff << i)).value + 1, 2)) for i in range(32)]
    [32, 31, 31, 29, 28, 28, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    >>> [32 - int(round(math.log(ctypes.c_uint32(~(0xffffffff << i)).value + 1, 2), 1)) for i in range(32)]
    [32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
latest commit 72447f7dfd
Carlo Contavalli authored

README.mkdn

pynetlinux: Linux network configuration library for Python

This library contains Python bindings to ioctl calls

Features

  • ifconfig

    • List interfaces
    • Bringing interfaces up and down
    • Setting and getting the IP address and netmask
    • Setting and getting link mode
    • Ethernet flow control
    • Retrieve interface statistics (bytes/packets tx/rx, etc)
  • brctl

    • Create and destroy bridges
    • Add/remove interfaces to bridges
    • Set forwarding delay
  • tap

    • Create and destroy taps
    • File object API
  • route

    • Get default gateway / interface

Contributors

  • Roman Lisagor
  • Sam Roberts
  • Anoop Karollil
  • Richard Feng
Something went wrong with that request. Please try again.