#!/usr/bin/perl

use IO::Socket::INET;
# flush after every write
$| = 1;

if ($#ARGV < 1) {
    print q{
=============================================================
|  Very simple query script for Quake 3 Engine Gameserver   |
|   it allows you to send any command to the server and     |
|              display the returned data                    |
|           finalized by Schnoog@Wolffiles.de               |
|                 Version 1.0                               |
|-----------------------------------------------------------|
|             Syntax - file.pl IP PORT COMMAND              |
|    f.e. ./file.pl 123.123.123.123 27960 "getstatus"       |
=============================================================
};
    exit;
}

my $add = $ARGV[0];
my $port = $ARGV[1];
my $cmd = $ARGV[2];
my ($socket,$client_socket);

$socket = new IO::Socket::INET (PeerHost => $add,PeerPort => $port,Proto => 'udp',) or die "ERROR in Socket Creation : $!\n.";

print "Connection Success";
$data = "\xff\xff\xff\xff$cmd";
print $socket "$data";
$socket->recv($data,1024);
print "Received from Server  $data \n";
$socket->close();
