dnet (version 1.9)
index
dnet.so

dumb networking library
 
This module provides a simplified interface to several low-level
networking routines, including network address manipulation, kernel
arp(4) cache and route(4) table lookup and manipulation, network
firewalling, network interface lookup and manipulation, IP tunnelling,
and raw IP packet and Ethernet frame transmission.

 
Modules
       
__builtin__

 
Classes
       
__builtin__.object
addr
arp
eth
fw
intf
ip
rand
route
tun

 
class addr(__builtin__.object)
    addr(addrtxt=None) -> network address object
 
Create a network address object (optionally from its human-readable
representation). Ethernet, IP, and IPv6 address types are currently
supported.
 
  Methods defined here:
__add__(...)
x.__add__(y) <==> x+y
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
x.__contains__(y) <==> y in x
__copy__(...)
__hash__(...)
x.__hash__() <==> hash(x)
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__int__(...)
x.__int__() <==> int(x)
__iter__(...)
x.__iter__() <==> iter(x)
__long__(...)
x.__long__() <==> long(x)
__radd__(...)
x.__radd__(y) <==> y+x
__repr__(...)
x.__repr__() <==> repr(x)
bcast(...)
Return an addr object for our broadcast address.
net(...)
Return an addr object for our network address.

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T
bits = <attribute 'bits' of 'dnet.addr' objects>
Address bitlength integer.
eth = <attribute 'eth' of 'dnet.addr' objects>
Ethernet MAC address as binary string.
ip = <attribute 'ip' of 'dnet.addr' objects>
IPv4 address as binary string.
ip6 = <attribute 'ip6' of 'dnet.addr' objects>
IPv6 address as binary string.
type = <attribute 'type' of 'dnet.addr' objects>
Address type (ADDR_TYPE_*) integer.

 
class arp(__builtin__.object)
    arp() -> ARP table object
 
Open a handle to the system ARP table.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__iter__(...)
x.__iter__() <==> iter(x)
add(...)
Add an entry to the system ARP table.
 
Arguments:
pa -- ADDR_TYPE_IP network address object
ha -- ADDR_TYPE_ETH network address object
delete(...)
Delete an entry from the system ARP table.
 
Arguments:
pa -- ADDR_TYPE_IP network address object
get(...)
Return the hardware address for a given protocol address
in the system ARP table.
 
Arguments:
pa -- ADDR_TYPE_IP network address object
loop(...)
Iterate over the system ARP table, invoking a user callback
with each entry, returning the status of the callback routine.
 
Keyword arguments:
callback -- callback function with ((pa, ha), arg) prototype.
            If this function returns a non-zero value, the loop
            will break early.
arg      -- optional callback argument

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class eth(__builtin__.object)
    eth(device) -> Ethernet device object
 
Open the specified Ethernet device for sending.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
get(...)
Return the MAC address associated with the device as a
binary string.
send(...)
Send an Ethernet frame, returning the number of bytes sent
or -1 on failure.
 
Arguments:
frame -- binary string representing an Ethernet frame
set(...)
Set the MAC address for the device, returning 0 on success,
-1 on failure.
 
Arguments:
eth_addr -- 6-byte binary string (e.g. '\x00\xde\xad\xbe\xef\x00')

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class fw(__builtin__.object)
    fw() -> Firewall ruleset object
 
Open a handle to the local network firewall configuration.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__iter__(...)
x.__iter__() <==> iter(x)
add(...)
Add a firewall rule specified as a dict.
 
Dict values:
device -- interface name                        (string)
op     -- operation (FW_OP_*)                   (integer)
dir    -- direction (FW_DIR_*)                  (integer)
proto  -- IP protocol (IP_PROTO_*)              (integer)
src    -- source address / net                  (addr object)
dst    -- destination address / net             (addr object)
sport  -- source port range or ICMP type/mask   (list of 2 integers)
dport  -- dest port range or ICMP code/mask     (list of 2 integers)
delete(...)
Delete a firewall rule specified as a dict.
loop(...)
Iterate over the local firewall ruleset, invoking a user callback
with each entry, returning the status of the callback routine.
 
Keyword arguments:
callback -- callback function with (dict, arg) prototype.
            If this function returns a non-zero value, the loop
            will break early.
arg      -- optional callback argument

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class intf(__builtin__.object)
    intf() -> Interface table object
 
Open a handle to the system network interface table.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__iter__(...)
x.__iter__() <==> iter(x)
get(...)
Return the configuration for a network interface as a dict.
get_dst(...)
Return the configuration for the best interface with which to
reach the specified dst address.
get_src(...)
Return the configuration for the interface whose primary address
matches the specified source address.
loop(...)
Iterate over the system interface table, invoking a user callback
with each entry, returning the status of the callback routine.
 
Keyword arguments:
callback -- callback function with (dict, arg) prototype.
            If this function returns a non-zero value, the loop
            will break early.
arg      -- optional callback argument
set(...)
Set the configuration for an interface from a dict.
 
Dict values:
name        -- name of interface to set         (string)
flags       -- interface flags (INTF_FLAG_*)    (integer bitmask)
mtu         -- interface MTU                    (integer)
addr        -- primary network address          (addr object)
dst_addr    -- point-to-point dst address       (addr object)
link_addr   -- link-layer address               (addr object)
alias_addrs -- additional network addresses     (list of addr objects)

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class ip(__builtin__.object)
    ip() -> Raw IP object
 
Open a raw IP socket for sending.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
send(...)
Send an IP packet, returning the number of bytes sent
or -1 on failure.
 
Arguments:
pkt -- binary string representing an IP packet

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class rand(__builtin__.object)
    rand() -> Pseudo-random number generator
 
Obtain a handle for fast, cryptographically strong pseudo-random
number generation. The starting seed is derived from the system
random data source device (if one exists), or from the current time
and random stack contents.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
add(...)
Add additional entropy into the PRNG mix.
 
Arguments:
string -- binary string
get(...)
Return a string of random bytes.
 
Arguments:
len -- number of random bytes to generate
set(...)
Initialize the PRNG from a known seed.
 
Arguments:
string -- binary string seed value
uint16(...)
Return a random 16-bit integer.
uint32(...)
Return a random 32-bit integer.
uint8(...)
Return a random 8-bit integer.
xrange(...)
xrange([start,] stop) -> xrange object
 
Return a random permutation iterator to walk an unsigned integer range,
like xrange().

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class route(__builtin__.object)
    route() -> Routing table object
 
Open a handle to the system routing table.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__iter__(...)
x.__iter__() <==> iter(x)
add(...)
Add an entry to the system routing table.
 
Arguments:
dst -- ADDR_TYPE_IP network address object
gw -- ADDR_TYPE_IP network address object
delete(...)
Delete an entry from the system routing table.
 
Arguments:
dst -- ADDR_TYPE_IP network address object
get(...)
Return the hardware address for a given protocol address
in the system routing table.
 
Arguments:
dst -- ADDR_TYPE_IP network address object
loop(...)
Iterate over the system routing table, invoking a user callback
with each entry, returning the status of the callback routine.
 
Keyword arguments:
callback -- callback function with ((dst, gw), arg) prototype.
            If this function returns a non-zero value, the loop
            will break early.
arg      -- optional callback argument

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class tun(__builtin__.object)
    tun(src, dst[, mtu]) -> Network tunnel interface handle
 
Obtain a handle to a network tunnel interface, to which packets
destined for dst are delivered (with source addresses rewritten to
src), where they may be read by a userland process and processed
as desired. Packets written back to the handle are injected into
the kernel networking subsystem.
 
  Methods defined here:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
close(...)
fileno(...)
Return file descriptor for tunnel handle.
recv(...)
Return the next packet delivered to the tunnel interface.
send(...)
Send an IP packet, returning the number of bytes sent
or -1 on failure.
 
Arguments:
pkt -- binary string representing an IP packet

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T
fd = <attribute 'fd' of 'dnet.tun' objects>
File descriptor for tunnel handle.
name = <attribute 'name' of 'dnet.tun' objects>
Tunnel interface name.

 
Functions
       
arp_pack_hdr_ethip(...)
Return a packed binary string representing an Ethernet/IP ARP message.
 
Keyword arguments:
op  -- operation (ARP_OP_*)                 (16-bit integer)
sha -- sender Ethernet address              (6-byte binary string)
spa -- sender IP address                    (4-byte binary string)
dha -- destination Ethernet address         (6-byte binary string)
dpa -- destination IP address               (4-byte binary string)
eth_aton(...)
Convert an Ethernet MAC address from a printable string to a
packed binary string ('\x00\xde\xad\xbe\xef\x00').
eth_ntoa(...)
Convert an Ethernet MAC address from 6-byte packed binary string to
a printable string ('00:de:ad:be:ef:00').
eth_pack_hdr(...)
Return a packed binary string representing an Ethernet header.
    
Keyword arguments:
dst  -- destination address                 (6-byte binary string)
src  -- source address                      (6-byte binary string)
type -- Ethernet payload type (ETH_TYPE_*)  (16-bit integer)
icmp_pack_hdr(...)
Return a packed binary string representing an ICMP header.
 
Keyword arguments:
type -- ICMP type           (8-bit integer)
code -- ICMP code           (8-bit integer)
ip6_aton(...)
Convert an IPv6 address from a printable string to a
packed binary string ('\x0a\x00\x00\x01').
ip6_checksum(...)
Return a packed binary string representing an IPv6 packet 
with the IPv6 and transport-layer checksums set.
 
Arguments:
pkt -- binary string representing an IPv6 packet
ip6_ntoa(...)
Convert an IPv6 address from a 16-byte packed binary string to a
printable string ('10.0.0.1').
ip6_pack_hdr(...)
Return a packed binary string representing an IPv6 header.
 
Keyword arguments:
fc   -- flow class                  (8-bit integer)
fl   -- flow label                  (20-bit integer)
plen -- payload length              (16-bit integer)
nxt  -- next header (IP_PROTO_*)    (8-bit integer)
hlim -- hop limit                   (8-bit integer)
src  -- source address              (16-byte binary string)
dst  -- destination address         (16-byte binary string)
ip_aton(...)
Convert an IP address from a printable string to a
packed binary string ('\x0a\x00\x00\x01').
ip_checksum(...)
XXX - modify packed binary string representing an IP packet 
by setting the IP and transport-layer checksums. The string's hash
is invalid after this. use dpkt instead!
 
Arguments:
pkt -- binary string representing an IP packet
ip_cksum_add(...)
ip_cksum_carry(...)
ip_ntoa(...)
Convert an IP address from a 4-byte packed binary string or
integer to a printable string ('10.0.0.1').
ip_pack_hdr(...)
Return a packed binary string representing an IP header.
 
Keyword arguments:
tos  -- type of service                     (8-bit integer)
len -- length (IP_HDR_LEN + payload)        (16-bit integer)
id   -- packet ID                           (16-bit integer)
off  -- fragmentation offset                (16-bit integer)
ttl  -- time-to-live                        (8-bit integer)
p    -- protocol (IP_PROTO_*)               (8-bit integer)
src  -- source address                      (4-byte binary string)
dst  -- destination address                 (4-byte binary string)
tcp_pack_hdr(...)
Return a packed binary string representing a TCP header.
 
Keyword arguments:
sport -- source port                (16-bit integer)
dport -- destination port           (16-bit integer)
seq   -- sequence number            (32-bit integer)
ack   -- acknowledgment number      (32-bit integer)
flags -- control flags (TH_*)       (8-bit integer bitmask)
win   -- window size                (16-bit integer)
urp   -- urgent pointer             (16-bit integer)
udp_pack_hdr(...)
Return a packed binary string representing a UDP header.
 
Keyword arguments:
sport -- source port                (16-bit integer)
dport -- destination port           (16-bit integer)
ulen  -- UDP header + data length   (16-bit integer)

 
Data
        ADDR_TYPE_ETH = 1
ADDR_TYPE_IP = 2
ADDR_TYPE_IP6 = 3
ADDR_TYPE_NONE = 0
ARP_ETHIP_LEN = 20
ARP_HDR_LEN = 8
ARP_HRD_ETH = 1
ARP_HRD_IEEE802 = 6
ARP_OP_REPLY = 2
ARP_OP_REQUEST = 1
ARP_OP_REVREPLY = 4
ARP_OP_REVREQUEST = 3
ARP_PRO_IP = 2048
ETH_ADDR_BITS = 48
ETH_ADDR_BROADCAST = '\xff\xff\xff\xff\xff\xff'
ETH_ADDR_LEN = 6
ETH_ADDR_UNSPEC = '\x00\x00\x00\x00\x00\x00'
ETH_CRC_LEN = 4
ETH_HDR_LEN = 14
ETH_LEN_MAX = 1518
ETH_LEN_MIN = 64
ETH_MIN = 46
ETH_MTU = 1500
ETH_TYPE_8021Q = 33024
ETH_TYPE_ARP = 2054
ETH_TYPE_IP = 2048
ETH_TYPE_IPV6 = 34525
ETH_TYPE_LEN = 2
ETH_TYPE_LOOPBACK = 36864
ETH_TYPE_MPLS = 34887
ETH_TYPE_MPLS_MCAST = 34888
ETH_TYPE_PPPOE = 34916
ETH_TYPE_PPPOEDISC = 34915
ETH_TYPE_PUP = 512
ETH_TYPE_REVARP = 32821
FW_DIR_IN = 1
FW_DIR_OUT = 2
FW_OP_ALLOW = 1
FW_OP_BLOCK = 2
INTF_FLAG_BROADCAST = 16
INTF_FLAG_LOOPBACK = 2
INTF_FLAG_MULTICAST = 32
INTF_FLAG_NOARP = 8
INTF_FLAG_POINTOPOINT = 4
INTF_FLAG_UP = 1
INTF_TYPE_ETH = 6
INTF_TYPE_LOOPBACK = 24
INTF_TYPE_OTHER = 1
INTF_TYPE_TUN = 53
IP6_ADDR_BITS = 128
IP6_ADDR_LEN = 16
IP6_ADDR_LOOPBACK = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
IP6_ADDR_UNSPEC = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
IP6_HDR_LEN = 40
IP6_HLIM_DEFAULT = 64
IP6_HLIM_MAX = 255
IP6_LEN_MAX = 65535
IP6_LEN_MIN = 40
IP6_MTU_MIN = 1280
IP_ADDR_ANY = '\x00\x00\x00\x00'
IP_ADDR_BITS = 32
IP_ADDR_BROADCAST = '\xff\xff\xff\xff'
IP_ADDR_LEN = 4
IP_ADDR_LOOPBACK = '\x7f\x00\x00\x01'
IP_ADDR_MCAST_ALL = '\xe0\x00\x00\x01'
IP_ADDR_MCAST_LOCAL = '\xe0\x00\x00\xff'
IP_DF = 16384
IP_HDR_LEN = 20
IP_HDR_LEN_MAX = 60
IP_LEN_MAX = 65535
IP_LEN_MIN = 20
IP_MF = 8192
IP_OFFMASK = 8191
IP_OPT_LEN = 2
IP_OPT_LEN_MAX = 40
IP_PROTO_AH = 51
IP_PROTO_ESP = 50
IP_PROTO_GRE = 47
IP_PROTO_ICMP = 1
IP_PROTO_ICMPV6 = 58
IP_PROTO_IGMP = 2
IP_PROTO_IP = 0
IP_PROTO_IPV6 = 41
IP_PROTO_MAX = 255
IP_PROTO_RAW = 255
IP_PROTO_RESERVED = 255
IP_PROTO_TCP = 6
IP_PROTO_UDP = 17
IP_RF = 32768
IP_TOS_DEFAULT = 0
IP_TTL_DEFAULT = 64
IP_TTL_MAX = 255
TCP_HDR_LEN = 20
TCP_OPT_ALTSUM = 14
TCP_OPT_ALTSUMDATA = 15
TCP_OPT_BUBBA = 17
TCP_OPT_CC = 11
TCP_OPT_CCECHO = 13
TCP_OPT_CCNEW = 12
TCP_OPT_CORRUPT = 23
TCP_OPT_ECHO = 6
TCP_OPT_ECHOREPLY = 7
TCP_OPT_EOL = 0
TCP_OPT_MAX = 27
TCP_OPT_MD5 = 19
TCP_OPT_MSS = 2
TCP_OPT_NOP = 1
TCP_OPT_POCONN = 9
TCP_OPT_POSVC = 10
TCP_OPT_REC = 22
TCP_OPT_SACK = 5
TCP_OPT_SACKOK = 4
TCP_OPT_SCPS = 20
TCP_OPT_SKEETER = 16
TCP_OPT_SNACK = 21
TCP_OPT_SNAP = 24
TCP_OPT_TCPCOMP = 26
TCP_OPT_TIMESTAMP = 8
TCP_OPT_TRAILSUM = 18
TCP_OPT_WSCALE = 3
TCP_PORT_MAX = 65535
TCP_WIN_MAX = 65535
TH_ACK = 16
TH_CWR = 128
TH_ECE = 64
TH_FIN = 1
TH_PUSH = 8
TH_RST = 4
TH_SYN = 2
TH_URG = 32
UDP_HDR_LEN = 8
UDP_PORT_MAX = 65535
__author__ = 'Dug Song <dugsong@monkey.org>'
__copyright__ = 'Copyright (c) 2003 Dug Song'
__license__ = 'BSD'
__url__ = 'http://libdnet.sourceforge.net/'
__version__ = '1.9'

 
Author
        Dug Song <dugsong@monkey.org>