2 ######################################################################
4 ## Copyright (C) 2001-2002,
5 ## Department of Computer Science, University of Tromsø, Norway.
7 ## For distribution policy, see the accompanying file COPYING.
9 ## Filename: udp6-send.py
10 ## Description: Send a simple (IPv6) UDP packet
11 ## Author: Frode Vatvedt Fjeld <frodef@acm.org>
12 ## Created at: Sun Mar 10 20:20:11 2002
14 ## $Id: udp6-send.py,v 1.1 2004/01/13 11:04:59 ffjeld Exp $
16 ######################################################################
18 import sys
,time
,socket
20 if len (sys
.argv
) != 4:
21 print "Usage: udp6-send <host> <port> <data>"
29 packets
= (len (data
) / mtu
) + 1
31 # print "host:", host, "port:", port, "data:", data
33 af
, socktype
, proto
, canonname
, sa
= \
34 socket
.getaddrinfo(host
, port
, socket
.AF_UNSPEC
, socket
.SOCK_DGRAM
)[0]
35 s
= socket
.socket (af
, socktype
, proto
)
37 for i
in range (packets
):
38 print "sending packet", i
, ".."
39 s
.send ("%d %d %s" % (i
+1, packets
, data
[i
*mtu
:min(i
*mtu
+mtu
, len (data
))]))