Skip to content

Commit 50e9236

Browse files
committed
Extract out reuseable local-proxy-addresses logic
1 parent e7ce6c3 commit 50e9236

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/interceptors/android/android-adb-interceptor.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import _ from 'lodash';
2-
import * as os from 'os';
32
import { DeviceClient } from '@devicefarmer/adbkit';
43

54
import { Interceptor } from '..';
@@ -24,6 +23,7 @@ import {
2423
} from './adb-commands';
2524
import { streamLatestApk, clearAllApks } from './fetch-apk';
2625
import { parseCert, getCertificateFingerprint, getCertificateSubjectHash } from '../../certificates';
26+
import { getReachableInterfaces } from '../../util/network';
2727

2828
function urlSafeBase64(content: string) {
2929
return Buffer.from(content, 'utf8').toString('base64')
@@ -98,17 +98,9 @@ export class AndroidAdbInterceptor implements Interceptor {
9898
'10.0.3.2', // Genymotion localhost ip
9999
].concat(
100100
// Every other external network ip
101-
_.flatMap(os.networkInterfaces(), (addresses, iface) =>
102-
(addresses || [])
103-
.filter(a =>
104-
!a.internal && // Loopback interfaces
105-
a.family === "IPv4" && // Android VPN app supports IPv4 only
106-
iface !== 'docker0' && // Docker default bridge interface
107-
!iface.startsWith('br-') && // More docker bridge interfaces
108-
!iface.startsWith('veth') // Virtual interfaces for each docker container
109-
)
110-
.map(a => a.address)
111-
)
101+
getReachableInterfaces().filter(a =>
102+
a.family === "IPv4" // Android VPN app supports IPv4 only
103+
).map(a => a.address)
112104
),
113105
port: proxyPort,
114106
localTunnelPort: proxyPort,

src/util/network.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as _ from 'lodash';
2+
import * as os from 'os';
3+
4+
export function getReachableInterfaces() {
5+
return _.flatMap(os.networkInterfaces(), (addresses, iface) =>
6+
(addresses || [])
7+
.filter(a =>
8+
!a.internal && // Loopback interfaces
9+
iface !== 'docker0' && // Docker default bridge interface
10+
!iface.startsWith('br-') && // More docker bridge interfaces
11+
!iface.startsWith('veth') // Virtual interfaces for each docker container
12+
)
13+
)
14+
}

0 commit comments

Comments
 (0)