Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Linux network configuration library for 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 November 14, 2013
Octocat-spinner-32 debian Packaged for Debian January 18, 2010
Octocat-spinner-32 pynetlinux Bugfix: current code computes the wrong netmask on some architectures. November 14, 2013
Octocat-spinner-32 .gitignore Packaged for Debian January 18, 2010
Octocat-spinner-32 LICENSE.txt Added a license January 18, 2010
Octocat-spinner-32 MANIFEST.in Including debian packaging in the source distribution January 19, 2010
Octocat-spinner-32 README.mkdn Fixed formatting in readme file January 18, 2010
Octocat-spinner-32 setup.py Bumped version number December 17, 2012
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.