def getSource(self):
        "Pick random source port to avoid DNS cache poisoning attack."
        while True:
            try:
                source_port = random.randint(1024,65535)
                self.s.bind(('', source_port))
                break
            except socket.error, msg: 
                # Error 98, 'Address already in use'
                if msg[0] != 98: raise
Pick random source port to avoid DNS cache poisoning attack.
python/DNS/Base.py