Automatyzacja łaczenia telnet... :/
Marcin Kasperski
Marcin.Kasperski w softax.com.pl
Śro, 17 Paź 2007, 16:20:55 BST
"Damian Kmiecik" <d0zoenator w gmail.com> writes:
> > Moja sugestia: nie używaj programu telnet. Napisz sobie skrypt
> > w perlu przy użyciu Net::Telnet, albo w pythonie przy pomocy
> > telnetlib.
>
> A czy jest jakaś biblioteka implementująca telnet w C++ albo C?
Na pewno. Na pewno wiele. Nie polecę żadnej, bo programowanie tego
typu rzeczy w C++ jest zupełnym overkillem.
Tak na zachętę przykłady z standardowej dokumentacji
(perl)
#!/usr/bin/perl
my ($forecast, $t);
use Net::Telnet ();
$t = new Net::Telnet;
$t->open("rainmaker.wunderground.com");
## Wait for first prompt and "hit return".
$t->waitfor('/continue:.*$/');
$t->print("");
## Wait for second prompt and respond with city code.
$t->waitfor('/city code.*$/');
$t->print("BRD");
## Read and print the first page of forecast.
($forecast) = $t->waitfor('/[ \t]+press return to continue/i');
print $forecast;
exit;
(python)
#!/usr/bin/python
import getpass
import sys
import telnetlib
HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()
Więcej informacji o liście dyskusyjnej ubuntu-pl