Buongiorno a tutti.<div>Tramite python (utilizzando l'esempio presente sulla documentazione della libreria telnetlib) riesco a connettermi, tramite telnet, al mio router.
</div><div><br></div><div>Ecco il codice del mio file "test.py"</div><div><br></div><div><div>import getpass</div><div>import sys</div><div>import telnetlib</div><div><br></div><div>HOST = "192.168.1.2"</div>
<div>user = raw_input("Utente: ")</div><div>password = getpass.getpass()</div><div><br></div><div>tn = telnetlib.Telnet(HOST)</div><div><br></div><div>tn.read_until("login: ")</div><div>tn.write(user + "\n")</div>
<div>if password:</div><div>    tn.read_until("Password: ")</div><div>    tn.write(password + "\n")</div><div><br></div><div>tn.write("help \n")</div><div>tn.write("exit\n")</div><div>
<br></div><div>print tn.read_all()</div></div><div><br></div><div><br></div><div><br></div><div>Cosě facendo, mi vengono forniti tutti i possibili comandi che posso lanciare.</div><div><br></div><div>~ # help </div><div><br>
</div><div>Built-in commands:</div><div>-------------------</div><div>        . : break cd chdir continue eval exec exit export false hash</div><div>        help local pwd read readonly return set shift source times trap</div>
<div>        true type ulimit umask unset wait [ [[ ash cat chgrp chmod chown</div><div>        cp date dd df echo egrep false fgrep free grep halt ifconfig</div><div>        insmod kill killall klogd ln login ls lsmod mesg mkdir modprobe</div>
<div>        more mv netstat nslookup ping pivot_root poweroff ps pwd reboot</div><div>        rm rmdir rmmod route sh sleep sync syslogd tail telnetd test</div><div>        tftp top touch traceroute true uname uptime vi watch wget who</div>
<div>        whoami</div><div><br></div><div><br></div><div>Non riesco a capire come funziona il "write":</div><div>- scrive tutto quanto e poi, una volta lanciato read_all esegue e legge i risultati</div><div>- esegue il comando fornito e il read_all legge solamente i risultati??</div>
<div><br></div><div>E' per capire come poter fare un ping (per esempio)</div><div><br></div><div>Grazie </div><div><br></div>