MCPcopy
hub / github.com/garrytan/gstack / getDeviceTunnelIPv6FromDevicectl

Function getDeviceTunnelIPv6FromDevicectl

ios-qa/daemon/src/devicectl.ts:110–133  ·  view source on GitHub ↗
(
  udid: string,
  spawn: SpawnImpl = defaultSpawn,
)

Source from the content-addressed store, hash-verified

108 * fails — callers should fall through to mDNS resolution.
109 */
110export function getDeviceTunnelIPv6FromDevicectl(
111 udid: string,
112 spawn: SpawnImpl = defaultSpawn,
113): string | null {
114 const tmp = join(tmpdir(), `devicectl-details-${process.pid}-${Date.now()}.json`);
115 try {
116 const r = spawn('xcrun', ['devicectl', 'device', 'info', 'details', '--device', udid, '--json-output', tmp]);
117 if (r.status !== 0) return null;
118 const raw = readFileSync(tmp, 'utf-8');
119 const obj = JSON.parse(raw);
120 // `result.connectionProperties.tunnelIPAddress` is the canonical location.
121 // Some Xcode/CoreDevice versions also surface it under `result.tunnel.ipAddress`
122 // — accept either.
123 const conn = obj?.result?.connectionProperties as Record<string, unknown> | undefined;
124 const tunnel = obj?.result?.tunnel as Record<string, unknown> | undefined;
125 const addr = (conn?.tunnelIPAddress ?? tunnel?.ipAddress) as string | undefined;
126 if (typeof addr === 'string' && addr.includes(':')) return addr;
127 return null;
128 } catch {
129 return null;
130 } finally {
131 try { rmSync(tmp, { force: true }); } catch { /* ignore */ }
132 }
133}
134
135/**
136 * Start a periodic devicectl `info details` poll that keeps the CoreDevice

Callers 2

resolveTunnelIPv6Function · 0.85

Calls 1

spawnFunction · 0.85

Tested by

no test coverage detected