-
-
Save gleero/4c45ad1112b083248fe715c9726f828b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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