INNER CODE UNIT · Python

detect_host_ip_for_endpoint

cvet/fonline · BuildTools/android_device.py:128

def detect_host_ip_for_endpoint(endpoint: str) -> str:
	host, port = split_endpoint(endpoint)

	try:
		with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as udp_socket:
			udp_socket.connect((host, port))
			local_ip = udp_socket.getsockname()[0]
	except OSError as exc:
		raise SystemExit(f'Unable to determine host IP for Android device {endpoint}: {exc}') from exc

	if not local_ip or local_ip.startswith('127.'):
		raise SystemExit(
			'Unable to determine a routable host IP for the Android device; use --server-host to specify it explicitly',
		)

	return local_ip

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…