#!/usr/bin/perl use strict; use warnings; use IO::Socket; my ($server, $port, $keyfile, $choosed); sub readconfig() { open(CONFIG,"config.cfg") or die "Error: Cant open config.cfg"; my @config=; close(CONFIG); chomp($server = $config[0]);        if ($server eq "") { die ("Error: No Server specified"); } chomp($port = $config[1]); if ($port eq "") { die ("Error: No Port specified"); } chomp($keyfile = $config[2]); if ($keyfile eq "") { die ("Error: No Keyfile specified"); } } sub writeconfig() { print ("Config\n------\n"); print ("Server: "); my $server = ; print ("\nPort: "); my $port = ; if ($port =~ m/[a-z]+/) { die ("Port must be a number!"); }        print ("\nKeyfile: "); my $keyfile = ; print ("Config written to config.cfg\n"); my @config = ($server, $port, $keyfile); open(CONFIG,">config.cfg"); print CONFIG (@config); close (CONFIG); } sub connection() { readconfig(); my $remote = IO::Socket::INET->new ( Proto => 'tcp', PeerAddr => $server, PeerPort => $port, Reuse => 1, ) or die "$!n"; print ("Connected to ", $remote->peerhost, " on port ",$remote->peerport, "\n\n"); $remote->autoflush(1); while ($remote) { my $line = <$remote>; open(KEYFILE,$keyfile);                my $crypt = ;                close(KEYFILE); if ($remote eq 'AUTH') { print $remote "$crypt"; } elsif ($remote eq 'AUTHED') { print $remote "TEST"; } else { print "Communication failed, exiting...\n"; exit; } } close $remote; } sub help() { print ("Valid commandline Options are:\n"); print ("-config -Initiates Configuration\n"); print ("-printcfg -Print Config\n"); print ("-connect -Connects to the Server\n"); } $choosed = $ARGV[0]; if ($choosed eq '-config') {        writeconfig();        exit 0; } elsif ($choosed eq '-printcfg') {        readconfig(); print ("Server: $server"); print ("Port: $port"); print ("Keyfile: $keyfile");        exit 0; } elsif ($choosed eq '-connect') {        connection();        exit 0; } else { help();        exit 0; }