Module dnet
[show private | hide private]
[frames | no frames]

Module dnet

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.

Classes
addr addr(addrtxt=None, type=ADDR_TYPE_NONE) -> network address object Create a network address object, optionally initialized from a human-readable Ethernet, IP, or IPv6 address string.
arp arp() -> ARP table object Open a handle to the system ARP table.
eth eth(device) -> Ethernet device object Open the specified Ethernet device for sending.
fw fw() -> Firewall ruleset object Open a handle to the local network firewall configuration.
intf intf() -> Interface table object Open a handle to the system network interface table.
ip ip() -> Raw IP object Open a raw IP socket for sending.
rand rand() -> Pseudo-random number generator Obtain a handle for fast, cryptographically strong pseudo-random number generation.
route route() -> Routing table object Open a handle to the system routing table.
tun 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.

Function Summary
  arp_pack_hdr_ethip(...)
Return a packed binary string representing an Ethernet/IP ARP message.
  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.
  icmp_pack_hdr(...)
Return a packed binary string representing an ICMP header.
  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.
  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.
  ip_aton(...)
Convert an IP address from a printable string to a packed binary string ('\x0a\x00\x00\x01').
  ip_checksum(...)
Return packed binary string representing an IP packet with the IP and transport-layer checksums set.
  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.
  tcp_pack_hdr(...)
Return a packed binary string representing a TCP header.
  udp_pack_hdr(...)
Return a packed binary string representing a UDP header.

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

Function Details

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(...)

Return packed binary string representing an IP packet 
with the IP and transport-layer checksums set.

Arguments:
pkt -- binary string representing an IP packet

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)

Variable Details

__author__

Type:
str
Value:
'Dug Song <dugsong@monkey.org>'                                        

__copyright__

Type:
str
Value:
'Copyright (c) 2003 Dug Song'                                          

__license__

Type:
str
Value:
'BSD'                                                                  

__url__

Type:
str
Value:
'http://libdnet.sourceforge.net/'                                      

__version__

Type:
str
Value:
'1.11'                                                                 

ADDR_TYPE_ETH

Type:
int
Value:
1                                                                     

ADDR_TYPE_IP

Type:
int
Value:
2                                                                     

ADDR_TYPE_IP6

Type:
int
Value:
3                                                                     

ADDR_TYPE_NONE

Type:
int
Value:
0                                                                     

ARP_ETHIP_LEN

Type:
int
Value:
20                                                                    

ARP_HDR_LEN

Type:
int
Value:
8                                                                     

ARP_HRD_ETH

Type:
int
Value:
1                                                                     

ARP_HRD_IEEE802

Type:
int
Value:
6                                                                     

ARP_OP_REPLY

Type:
int
Value:
2                                                                     

ARP_OP_REQUEST

Type:
int
Value:
1                                                                     

ARP_OP_REVREPLY

Type:
int
Value:
4                                                                     

ARP_OP_REVREQUEST

Type:
int
Value:
3                                                                     

ARP_PRO_IP

Type:
int
Value:
2048                                                                  

ETH_ADDR_BITS

Type:
int
Value:
48                                                                    

ETH_ADDR_BROADCAST

Type:
str
Value:
'\xff\xff\xff\xff\xff\xff'                                             

ETH_ADDR_LEN

Type:
int
Value:
6                                                                     

ETH_ADDR_UNSPEC

Type:
str
Value:
'\x00\x00\x00\x00\x00\x00'                                             

ETH_CRC_LEN

Type:
int
Value:
4                                                                     

ETH_HDR_LEN

Type:
int
Value:
14                                                                    

ETH_LEN_MAX

Type:
int
Value:
1518                                                                  

ETH_LEN_MIN

Type:
int
Value:
64                                                                    

ETH_MIN

Type:
int
Value:
46                                                                    

ETH_MTU

Type:
int
Value:
1500                                                                  

ETH_TYPE_8021Q

Type:
int
Value:
33024                                                                 

ETH_TYPE_ARP

Type:
int
Value:
2054                                                                  

ETH_TYPE_IP

Type:
int
Value:
2048                                                                  

ETH_TYPE_IPV6

Type:
int
Value:
34525                                                                 

ETH_TYPE_LEN

Type:
int
Value:
2                                                                     

ETH_TYPE_LOOPBACK

Type:
int
Value:
36864                                                                 

ETH_TYPE_MPLS

Type:
int
Value:
34887                                                                 

ETH_TYPE_MPLS_MCAST

Type:
int
Value:
34888                                                                 

ETH_TYPE_PPPOE

Type:
int
Value:
34916                                                                 

ETH_TYPE_PPPOEDISC

Type:
int
Value:
34915                                                                 

ETH_TYPE_PUP

Type:
int
Value:
512                                                                   

ETH_TYPE_REVARP

Type:
int
Value:
32821                                                                 

FW_DIR_IN

Type:
int
Value:
1                                                                     

FW_DIR_OUT

Type:
int
Value:
2                                                                     

FW_OP_ALLOW

Type:
int
Value:
1                                                                     

FW_OP_BLOCK

Type:
int
Value:
2                                                                     

INTF_FLAG_BROADCAST

Type:
int
Value:
16                                                                    

INTF_FLAG_LOOPBACK

Type:
int
Value:
2                                                                     

INTF_FLAG_MULTICAST

Type:
int
Value:
32                                                                    

INTF_FLAG_NOARP

Type:
int
Value:
8                                                                     

INTF_FLAG_POINTOPOINT

Type:
int
Value:
4                                                                     

INTF_FLAG_UP

Type:
int
Value:
1                                                                     

INTF_TYPE_ETH

Type:
int
Value:
6                                                                     

INTF_TYPE_LOOPBACK

Type:
int
Value:
24                                                                    

INTF_TYPE_OTHER

Type:
int
Value:
1                                                                     

INTF_TYPE_TUN

Type:
int
Value:
53                                                                    

IP6_ADDR_BITS

Type:
int
Value:
128                                                                   

IP6_ADDR_LEN

Type:
int
Value:
16                                                                    

IP6_ADDR_LOOPBACK

Type:
str
Value:
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'     

IP6_ADDR_UNSPEC

Type:
str
Value:
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'     

IP6_HDR_LEN

Type:
int
Value:
40                                                                    

IP6_HLIM_DEFAULT

Type:
int
Value:
64                                                                    

IP6_HLIM_MAX

Type:
int
Value:
255                                                                   

IP6_LEN_MAX

Type:
int
Value:
65535                                                                 

IP6_LEN_MIN

Type:
int
Value:
40                                                                    

IP6_MTU_MIN

Type:
int
Value:
1280                                                                  

IP_ADDR_ANY

Type:
str
Value:
'\x00\x00\x00\x00'                                                     

IP_ADDR_BITS

Type:
int
Value:
32                                                                    

IP_ADDR_BROADCAST

Type:
str
Value:
'\xff\xff\xff\xff'                                                     

IP_ADDR_LEN

Type:
int
Value:
4                                                                     

IP_ADDR_LOOPBACK

Type:
str
Value:
'\x7f\x00\x00\x01'                                                     

IP_ADDR_MCAST_ALL

Type:
str
Value:
'\xe0\x00\x00\x01'                                                     

IP_ADDR_MCAST_LOCAL

Type:
str
Value:
'\xe0\x00\x00\xff'                                                     

IP_DF

Type:
int
Value:
16384                                                                 

IP_HDR_LEN

Type:
int
Value:
20                                                                    

IP_HDR_LEN_MAX

Type:
int
Value:
60                                                                    

IP_LEN_MAX

Type:
int
Value:
65535                                                                 

IP_LEN_MIN

Type:
int
Value:
20                                                                    

IP_MF

Type:
int
Value:
8192                                                                  

IP_OFFMASK

Type:
int
Value:
8191                                                                  

IP_OPT_LEN

Type:
int
Value:
2                                                                     

IP_OPT_LEN_MAX

Type:
int
Value:
40                                                                    

IP_PROTO_AH

Type:
int
Value:
51                                                                    

IP_PROTO_ESP

Type:
int
Value:
50                                                                    

IP_PROTO_GRE

Type:
int
Value:
47                                                                    

IP_PROTO_ICMP

Type:
int
Value:
1                                                                     

IP_PROTO_ICMPV6

Type:
int
Value:
58                                                                    

IP_PROTO_IGMP

Type:
int
Value:
2                                                                     

IP_PROTO_IP

Type:
int
Value:
0                                                                     

IP_PROTO_IPV6

Type:
int
Value:
41                                                                    

IP_PROTO_MAX

Type:
int
Value:
255                                                                   

IP_PROTO_RAW

Type:
int
Value:
255                                                                   

IP_PROTO_RESERVED

Type:
int
Value:
255                                                                   

IP_PROTO_TCP

Type:
int
Value:
6                                                                     

IP_PROTO_UDP

Type:
int
Value:
17                                                                    

IP_RF

Type:
int
Value:
32768                                                                 

IP_TOS_DEFAULT

Type:
int
Value:
0                                                                     

IP_TTL_DEFAULT

Type:
int
Value:
64                                                                    

IP_TTL_MAX

Type:
int
Value:
255                                                                   

TCP_HDR_LEN

Type:
int
Value:
20                                                                    

TCP_OPT_ALTSUM

Type:
int
Value:
14                                                                    

TCP_OPT_ALTSUMDATA

Type:
int
Value:
15                                                                    

TCP_OPT_BUBBA

Type:
int
Value:
17                                                                    

TCP_OPT_CC

Type:
int
Value:
11                                                                    

TCP_OPT_CCECHO

Type:
int
Value:
13                                                                    

TCP_OPT_CCNEW

Type:
int
Value:
12                                                                    

TCP_OPT_CORRUPT

Type:
int
Value:
23                                                                    

TCP_OPT_ECHO

Type:
int
Value:
6                                                                     

TCP_OPT_ECHOREPLY

Type:
int
Value:
7                                                                     

TCP_OPT_EOL

Type:
int
Value:
0                                                                     

TCP_OPT_MAX

Type:
int
Value:
27                                                                    

TCP_OPT_MD5

Type:
int
Value:
19                                                                    

TCP_OPT_MSS

Type:
int
Value:
2                                                                     

TCP_OPT_NOP

Type:
int
Value:
1                                                                     

TCP_OPT_POCONN

Type:
int
Value:
9                                                                     

TCP_OPT_POSVC

Type:
int
Value:
10                                                                    

TCP_OPT_REC

Type:
int
Value:
22                                                                    

TCP_OPT_SACK

Type:
int
Value:
5                                                                     

TCP_OPT_SACKOK

Type:
int
Value:
4                                                                     

TCP_OPT_SCPS

Type:
int
Value:
20                                                                    

TCP_OPT_SKEETER

Type:
int
Value:
16                                                                    

TCP_OPT_SNACK

Type:
int
Value:
21                                                                    

TCP_OPT_SNAP

Type:
int
Value:
24                                                                    

TCP_OPT_TCPCOMP

Type:
int
Value:
26                                                                    

TCP_OPT_TIMESTAMP

Type:
int
Value:
8                                                                     

TCP_OPT_TRAILSUM

Type:
int
Value:
18                                                                    

TCP_OPT_WSCALE

Type:
int
Value:
3                                                                     

TCP_PORT_MAX

Type:
int
Value:
65535                                                                 

TCP_WIN_MAX

Type:
int
Value:
65535                                                                 

TH_ACK

Type:
int
Value:
16                                                                    

TH_CWR

Type:
int
Value:
128                                                                   

TH_ECE

Type:
int
Value:
64                                                                    

TH_FIN

Type:
int
Value:
1                                                                     

TH_PUSH

Type:
int
Value:
8                                                                     

TH_RST

Type:
int
Value:
4                                                                     

TH_SYN

Type:
int
Value:
2                                                                     

TH_URG

Type:
int
Value:
32                                                                    

UDP_HDR_LEN

Type:
int
Value:
8                                                                     

UDP_PORT_MAX

Type:
int
Value:
65535                                                                 

Generated by Epydoc 2.1 on Thu Jan 19 13:24:11 2006 http://epydoc.sf.net