Skip to content

Instantly share code, notes, and snippets.

@gleero
Last active October 11, 2023 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gleero/4c45ad1112b083248fe715c9726f828b to your computer and use it in GitHub Desktop.
Save gleero/4c45ad1112b083248fe715c9726f828b to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
$iport = int(rand(40000)) + 10000;
$first = 1;
foreach (@ARGV) {
if (/^--port=/) {
$args = "$_";
$args =~ /port=([0-9]+)?/;
$iport = int($1);
}
elsif (/^((.+)@)?([^:]+):?(\d+)?$/) {
$user = $1;
$host = $3;
$port = $4 || 22;
if ($first) {
$cmd = "ssh ${user}${host} -p $port -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
$args = '';
$first = 0;
}
else {
$cmd .= " -L 0.0.0.0:$iport:$host:$port";
push @cmds, "$cmd -f sleep 10 $args";
$cmd = "ssh ${user}localhost -p $iport -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
$args = '';
$iport ++;
}
}
}
push @cmds, "$cmd $args";
foreach (@cmds) {
print "$_\n";
system($_);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment