diff --git a/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/tcp_echo_client.py b/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/tcp_echo_client.py index 51a3c21c147..44ac15df252 100644 --- a/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/tcp_echo_client.py +++ b/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/tcp_echo_client.py @@ -128,7 +128,10 @@ def find_interface_to_target_addr(target_ip): :return: """ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect((target_ip, 0)) # Target IP, Any port + try: + s.connect((target_ip, 0)) # Target IP, any port + except socket.error: + s.connect((target_ip, 8000)) # Target IP, 'random' port ip = s.getsockname()[0] s.close() return ip diff --git a/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/udp_echo_client.py b/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/udp_echo_client.py index a2882c6aa20..9be3562da58 100644 --- a/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/udp_echo_client.py +++ b/features/FEATURE_LWIP/TESTS/mbedmicro-net/host_tests/udp_echo_client.py @@ -55,7 +55,10 @@ def find_interface_to_target_addr(target_ip): :return: """ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect((target_ip, 0)) # Target IP, Any port + try: + s.connect((target_ip, 0)) # Target IP, any port + except socket.error: + s.connect((target_ip, 8000)) # Target IP, 'random' port ip = s.getsockname()[0] s.close() return ip