Samples tips
Start and stop time and display
		
		tt=time.time()
		..
		..
		print "%.2f seconds" % (time.time() - tt)
Convert a Value (INT) into Hex String
		Oct1 = 3
		#convert int to hex
		oct1 = '%x'%(Oct1)
		#Add in leading 0 if hex string is single digit (i.e. Less than 0x10)
		if Oct1 < 16:
		    oct1='''0%x'''%(Oct1)
		else:
		    oct1='''%x'''%(Oct1)
		
		#Set IP options
		OCT1=r'\x%s'%(oct1)
string converting
	
# 
# Enter Oct1 - Oct4 -> Output is string
#
#
Oct1 = 3
Oct2 = 0
Oct3 = 4
Oct4 = 255
#convert int to hex
oct1 = '%x'%(Oct1)
oct2 = '%x'%(Oct2)
oct2 = '%x'%(Oct2)
oct2 = '%x'%(Oct2)
#Add in leading 0 if hex string is single digit (i.e. Less than 0x10)
if Oct1 < 16:
    oct1='''0%x'''%(Oct1)
else:
    oct1='''%x'''%(Oct1)

if Oct2 < 16:
    oct2='''0%x'''%(Oct2)
else:
    oct2='''%x'''%(Oct2)

if Oct3 < 16:
    oct3='''0%x'''%(Oct3)
else:
    oct3='''%x'''%(Oct3)

if Oct4 < 16:
    oct4='''0%x'''%(Oct4)
else:
    oct4='''%x'''%(Oct4)

#Set IP options
OCT_END=r'\x%s\x%s\x%s\x%s'%(oct1,oct2,oct3,oct4)
Some other samples for converting
>>> chr(0)
'\x00'

>>> struct.pack('!i', 3)
'\x00\x00\x00\x03'
>>> struct.pack('!i', 65535)
'\x00\x00\xff\xff'

Python random numbers
for ipv6 i need sometimes random IP's
	
import random
for i in range(100):
  x = random.random()
  print "%x" % int(x*65536)

(c) 2008 by packetlevel.ch / last update: 06.03.2009