def perform_m_search(local_ip):
 search_target = 'urn:schemas-upnp-org:device:InternetGatewayDevice:1'
 ssdp_request = ''.join(['M-SEARCH * HTTP/1.1\r\n', 'HOST: 239.255.255.250:1900\r\n', 'MAN: "ssdp:discover"\r\n', 'MX: 2\r\n', 'ST: {0}\r\n'.format(search_target), '\r\n'])
 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 sock.bind((local_ip, 10000))
 sock.sendto(ssdp_request, ('239.255.255.250', 1900))
 if (local_ip == '127.0.0.1'):
  sock.settimeout(1)
 else:
  sock.settimeout(5)
 try:
  return sock.recv(2048)
 except socket.error:
  raise UpnpError('No reply from IGD using {} as IP'.format(local_ip))
 finally:
  sock.close()

def perform_m_search ( local_ip ) : search_target = 'urn:schemas-upnp-org:device:InternetGatewayDevice:1' ssdp_request = '' . join ( [ 'M-SEARCH * HTTP/1.1\r\n' , 'HOST: 239.255.255.250:1900\r\n' , 'MAN: "ssdp:discover"\r\n' , 'MX: 2\r\n' , 'ST: {0}\r\n' . format ( search_target ) , '\r\n' ] ) sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) sock . bind ( ( local_ip , 10000 ) ) sock . sendto ( ssdp_request , ( '239.255.255.250' , 1900 ) ) if ( local_ip == '127.0.0.1' ) : sock . settimeout ( 1 ) else : sock . settimeout ( 5 ) try : return sock . recv ( 2048 ) except socket . error : raise UpnpError ( 'No reply from IGD using {} as IP' . format ( local_ip ) ) finally : sock . close ( )
broadcast a udp ssdp m-search packet and return response .