Found some code on the PYWEMO repository (line 18-64) on how they go about probing for which port to use:
# Start with the most commonly used port
PROBE_PORTS = (49153, 49152, 49154, 49151, 49155, 49156, 49157, 49158, 49159)
def probe_wemo(host, ports=PROBE_PORTS, probe_timeout=10):
Probe a host for the current port.
This probes a host for known-to-be-possible ports and
returns the one currently in use. If no port is discovered
then it returns None.
for port in ports:
response = requests.get('http://%s:%i/setup.xml' % (host, port),
if ('WeMo' in response.text) or ('Belkin' in response.text):
# If we timed out connecting, then the wemo is gone,
# no point in trying further.
LOG.debug('Timed out connecting to %s on port %i, '
'wemo is offline', host, port)
# Apparently sometimes wemos get into a wedged state where
# they still accept connections on an old port, but do not
# respond. If that happens, we should keep searching.
LOG.debug('No response from %s on port %i, continuing',
"""Probe a device for available port.
This is an extension for probe_wemo, also probing current port.
ports = list(PROBE_PORTS)
if device.port in ports:
return probe_wemo(device.host, ports)