How can I send data to Magma server without installing the client?
Posted: Mon Jul 18, 2016 6:33 pm
How can I send data to Magma without installing the client?
If you cannot install any "foreign" tools on your system, then sending data to Magma may be a challenge. But if you have access to either Perl, BASH or telnet on the system then it is possible.
Perl version:
BASH version:
NOTE: The BASH support for using TCP sockets may be disabled at compile-time - some believe it is a security risk to have such an easy way of doing network I/O without requiring any special tools.
Bourne / Korn shell (requires telnet):
Both of these take 2 or 3 parameters: The Magma server host (hostname or IP-address), optionally the portnumber (1984 by default if not specified), and the message that will be sent. The Perl version will both send data to Magma and print out any response that is sent back - the shell-versions can only be used to send data.
If you cannot install any "foreign" tools on your system, then sending data to Magma may be a challenge. But if you have access to either Perl, BASH or telnet on the system then it is possible.
Perl version:
Code: Select all
#!/usr/bin/perl
#
sub sendToMagma {
use IO::Socket;
my($server,$port,$msg) = @_ ;
my $response;
my $sock = new IO::Socket::INET (
PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print $sock $msg;
shutdown($sock, 1);
while ($response=<$sock>)
{
print "$response";
}
close($sock);
}
$host = $ARGV[0];
if ($#ARGV != 2) {
$port = 1984;
$msg = $ARGV[1];
}
else {
$port = $ARGV[1];
$msg = $ARGV[2];
}
sendToMagma($host, $port, $msg);
Code: Select all
#!/bin/bash
#
HOST="$1" ; shift
if test $# -gt 1; then
PORT="$1"
shift
else
PORT="1984"
fi
MSG="$1"
exec 3<>/dev/tcp/$HOST/$PORT || exit 1
echo "$MSG" >&3
exit 0
Bourne / Korn shell (requires telnet):
Code: Select all
#!/bin/sh
#
HOST="$1" ; shift
if test $# -gt 1; then
PORT="$1"
shift
else
PORT="1984"
fi
MSG="$1"
( echo "$MSG"; sleep 1 ) | telnet $HOST $PORT 2>&1 >/dev/null | grep -v "closed by foreign host"