#!/bin/bash

# A script that tries various methods to connect to...
host=$1
port=$2
secret=$3

exec 2>/dev/null # Be quiet about failures

echo "$secret" >/dev/tcp/$host/$port ||

echo "$secret" | nc $host $port ||

echo "\
use strict;
use IO::Socket;

my \$sock = new IO::Socket::INET (PeerAddr => '$host',
                                  PeerPort => '$port',
                                  Proto => 'tcp',
                                 );
die \"Could not create socket: \$!\n\" unless \$sock;
print \$sock \"$secret\n\";
close (\$sock);
" | perl ||

echo "\
import sys, socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('$host', $port))
s.send('$secret\n')
s.close()
" | python
