INNER CODE UNIT · Python

split_endpoint

cvet/fonline · BuildTools/android_device.py:120

def split_endpoint(endpoint: str) -> tuple[str, int]:
	normalized_endpoint = normalize_endpoint(endpoint)
	host, separator, port_text = normalized_endpoint.rpartition(':')
	if not separator or not host or not port_text.isdigit():
		raise SystemExit(f'Invalid Android device endpoint: {endpoint}')
	return host, int(port_text)


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

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…