-
-
Save cjsmeele/b022a1a0900105a69bddcfca9b2eb6d3 to your computer and use it in GitHub Desktop.
Small socat wrapper for my two most common usecases
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/env perl | |
use 5.12.0; | |
use warnings; | |
=head1 SYNOPSIS | |
sok [-PORT [SOCAT_FLAGS...]] | |
sok HOST [PORT [SOCAT_FLAGS...]] | |
=over 4 | |
=item C<sok [-PORT]> | |
listens on that TCP port (default 1234). | |
=item C<sok HOST [PORT]> | |
connects to that host on that TCP port (default 1234). | |
=back | |
=cut | |
my ($l, $host, $port); | |
if (not @ARGV) { | |
$l = 1; | |
$port = 1234 | |
} elsif ($ARGV[0] =~ /^-(\d+)?$/) { | |
$l = 1; | |
$port = $1 // 1234; | |
shift; | |
} else { | |
$host = shift; | |
$port = shift // 1234; | |
} | |
if ($l) { | |
exec "socat", @ARGV, "TCP-LISTEN:$port", "-" | |
} else { | |
exec "socat", @ARGV, "-", "TCP:$host:$port" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment