Skip to content

Instantly share code, notes, and snippets.

@MrHell0
Last active February 4, 2024 05:59
Show Gist options
  • Save MrHell0/7b5682cacaaafc68f2e5e0d047b6ff64 to your computer and use it in GitHub Desktop.
Save MrHell0/7b5682cacaaafc68f2e5e0d047b6ff64 to your computer and use it in GitHub Desktop.
tunnel to avalanchego node
#!/usr/bin/env node
# this script creates a tunnel from localhost:9650 to your avalanchego node
const fs = require('fs');
const readFileSync = fs.readFileSync;
// npm install -g tunnel-ssh
const tunnelSsh = require("tunnel-ssh");
async function main() {
if (process.argv.length < 3) {
console.error('Usage: tunnel x.x.x.x');
process.exit(1);
}
const ipaddress = process.argv[2];
const tunnelConfig = {
username: "username",
host: ipaddress,
dstHost: ipaddress,
dstPort: 9650,
localPort: 9650,
privateKey: readFileSync(`${process.env["HOME"]}/.ssh/your_key`),
keepAlive: true,
};
console.log(
`Starting tunnel for ${tunnelConfig.hostname} on port ${tunnelConfig.localPort}`
);
const t = tunnelSsh(tunnelConfig, function(error, server) {
if (error) {
console.error("Tunnel error: ", error);
process.exit(1);
}
});
t.on("error", (err) => {
console.error("Something bad happened:", err);
process.exit(1);
});
}
main().catch((e) => {
console.error(e);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment