@defer.inlineCallbacks
def _discover_multicast():
 nonce = str(random.randrange((2 ** 64)))
 p = _LocalNetworkMulticast(nonce)
 for attempt in itertools.count():
  port = (11000 + random.randint(0, 5000))
  try:
   mcast = reactor.listenMulticast(port, p)
  except CannotListenError:
   if (attempt >= 10):
    raise
   continue
  else:
   break
 try:
  (yield mcast.joinGroup('239.255.255.250', socket.INADDR_ANY))
  logging.debug('Sending multicast ping')
  for i in xrange(3):
   p.transport.write(nonce, ('239.255.255.250', port))
  (address,) = (yield p.address_received.get_deferred(5))
 finally:
  mcast.stopListening()
 defer.returnValue(address)

@ defer . inlineCallbacks def _discover_multicast ( ) : nonce = str ( random . randrange ( ( 2 ** 64 ) ) ) p = _LocalNetworkMulticast ( nonce ) for attempt in itertools . count ( ) : port = ( 11000 + random . randint ( 0 , 5000 ) ) try : mcast = reactor . listenMulticast ( port , p ) except CannotListenError : if ( attempt >= 10 ) : raise continue else : break try : ( yield mcast . joinGroup ( '239.255.255.250' , socket . INADDR_ANY ) ) logging . debug ( 'Sending multicast ping' ) for i in xrange ( 3 ) : p . transport . write ( nonce , ( '239.255.255.250' , port ) ) ( address , ) = ( yield p . address_received . get_deferred ( 5 ) ) finally : mcast . stopListening ( ) defer . returnValue ( address )
local ip discovery protocol via multicast: - broadcast 3 ping multicast packet with "ping" in it - wait for an answer - retrieve the ip address from the returning packet .