Skip to content

Commit

Permalink
Update IP testing script to signal just once, for the first good IP
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jun 3, 2024
1 parent a7f9bf4 commit b038788
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Each script includes detailed documentation on what it does and how it works in
You probably don't want to use this normally as part of interception itself, but it can be very useful as part of your configuration setup.

This script allows you to configure a list of possible IP addresses and a target port, and will then send the results of those connectivity tests for each IP:PORT address back to the Frida client, so you can confirm which IP address of a proxy host (e.g. your computer) is reachable from your target device.
This script allows you to configure a list of possible IP addresses and a target port, and have the process test each address, and send a message to the Frida client for the first reachable address provided. This can be useful for automated configuration processeses, if you don't know which IP address is best to use to reach the proxy server (your computer) from the target device (your phone).
---
Expand Down
39 changes: 26 additions & 13 deletions utilities/test-ip-connectivity.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/**
* This script is a little different from the others, and is designed to help with setup,
* particularly in automated scenarios, rather than supporting interception/unpinning/etc.
*
* Using this script, you can provide a list of IP addresses and a port, and the script will
* send messages back to your Frida client for each IP:PORT address that is reachable from
* the target device. When your proxy is running on a remote device from the target host,
* this can be useful to work out which proxy IP address should be used.
* This script can be useful as part of a pre-setup or automated configuration process,
* where you don't know why IP address is best used to reach your proxy server from the
* target device. You can run this script first with a list of IP addresses, and wait for
* the 'connected' message to confirm the working IP (or 'connection-failed' if none work)
* before then injecting the config script and the rest of your script code.
*
* Source available at https://github.com/httptoolkit/frida-interception-and-unpinning/
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -44,12 +42,27 @@ async function testAddress(ip, port) {
}
}

let completed = false;
let testsCompleted = 0;
IP_ADDRESSES_TO_TEST.forEach(async (ip) => {
const result = await testAddress(ip, TARGET_PORT);
send({
type: 'connectivity-result',
ip,
port: TARGET_PORT,
result
});
testsCompleted += 1;

if (completed) return; // Ignore results after the first connection

if (result) {
completed = true;
send({
type: 'connected',
ip,
port: TARGET_PORT
});
}

if (testsCompleted === IP_ADDRESSES_TO_TEST.length && !completed) {
completed = true;
send({
type: 'connection-failed'
});
}
});

0 comments on commit b038788

Please sign in to comment.