You can use Perl, it has module called Net::Telnet which can used to emulate a telnet connection through program!