scau l'ignoranza... ma come funziona? E' un comando telnet? (giusto per capire dove documentarmi)<br><br><div class="gmail_quote">Il giorno 04 maggio 2011 11:53, Andrea Tagliolini -Gmail <span dir="ltr"><<a href="mailto:andreatagliolini@gmail.com">andreatagliolini@gmail.com</a>></span> ha scritto:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

  
    
  
  <div text="#000000" bgcolor="#ffffff">
    Puoi anche controllare con il comando uptime, a quanto corrisponde
    "la vita" del router :)<br>
    <br>
    Il 04/05/2011 11:34, Nicola Ferrari ha scritto:
    <div><div></div><div class="h5"><blockquote type="cite">Se riesco ci darò un occhiata...
      <div>Una domanda "teorica"... una volta che da telnet faccio
        "reboot", per sapere se ha riavviato devo controllare se la rete
        è "su" giusto?? </div>
      <div>solo che nel momento in cui faccio reboot al momento in cui
        la rete "cade", passa un po' di tempo.. come faccio a risolvere?
        Faccio uno sleep ? </div>
      <div>Di quanti secondi?<br>
        <br>
        <div class="gmail_quote">Il giorno 04 maggio 2011 10:45, Andrea
          Tagliolini -Gmail <span dir="ltr"><<a href="mailto:andreatagliolini@gmail.com" target="_blank">andreatagliolini@gmail.com</a>></span>
          ha scritto:<br>
          <blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
            <div text="#000000" bgcolor="#ffffff"> Ok, naturalmente puoi
              fare come vuoi :)<br>
              Comunque ti dò un piccolo esempio di pexpect per fare un
              ping verso il dns di google nel router.<br>
              <br>
              import pexpect<br>
              <br>
              <br>
              telnet = pexpect.spawn("telnet 192.168.1.1")<br>
              telnet.expect("Login:")<br>
              telnet.sendline("username del tuo router")<br>
              telnet.expect("Password:")<br>
              telnet.sendline("password_del tuo router")<br>
              telnet.expect("#")<br>
              telnet.senline("ping -c 5 8.8.8.8")<br>
              telnet.expect("#")<br>
              telnet.interact()<br>
              <br>
              L'ho scritto al volo e potrebbero esserci errori, però in
              generale funziona cosi.<br>
              Io lo uso molto spesso in ambito lavorativo e funziona
              alla grande :)<br>
              <br>
              Ciao<br>
              <br>
              <br>
              Il 04/05/2011 10:22, Nicola Ferrari ha scritto:
              <div>
                <div>
                  <blockquote type="cite">
                    <blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"> Perchè non provi pexpect?</blockquote>
                    <div>Perchè telnetlib sembra più usata/documentata
                      (almeno, visto i risultati che mi fornisce google
                      quando ricerco python+telnet).</div>
                    <div><br>
                    </div>
                    <div> </div>
                    <br>
                    <div class="gmail_quote">2011/5/4 Andrea Tagliolini
                      -Gmail <span dir="ltr"><<a href="mailto:andreatagliolini@gmail.com" target="_blank">andreatagliolini@gmail.com</a>></span><br>
                      <blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
                        <div text="#000000" bgcolor="#ffffff"> Perchè
                          non provi pexpect?<br>
                          <br>
                          <a href="http://pexpect.sourceforge.net/pexpect.html" target="_blank">http://pexpect.sourceforge.net/pexpect.html</a><br>
                          <br>
                          Ciao<br>
                          <br>
                          Il 04/05/2011 10:00, Nicola Ferrari ha
                          scritto:
                          <blockquote type="cite">
                            <div>
                              <div>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>
                              </div>
                            </div>
                            <pre><fieldset></fieldset>
_______________________________________________
Python mailing list
<a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a>
<a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a>
</pre>
                          </blockquote>
                          <br>
                        </div>
                        <br>
                        _______________________________________________<br>
                        Python mailing list<br>
                        <a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a><br>
                        <a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a><br>
                        <br>
                      </blockquote>
                    </div>
                    <br>
                    <br clear="all">
                    <br>
                    -- <br>
                    Nicola Ferrari<br>
                    website: <a href="http://www.nicolaferrari.name" target="_blank">http://www.nicolaferrari.name</a><br>
                    <br>
                    skype: nick.ferro<br>
                    <br>
                    <pre><fieldset></fieldset>
_______________________________________________
Python mailing list
<a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a>
<a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a>
</pre>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            Python mailing list<br>
            <a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a><br>
            <a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a><br>
            <br>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <br>
        -- <br>
        Nicola Ferrari<br>
        website: <a href="http://www.nicolaferrari.name" target="_blank">http://www.nicolaferrari.name</a><br>
        <br>
        skype: nick.ferro<br>
        <br>
      </div>
      <pre><fieldset></fieldset>
_______________________________________________
Python mailing list
<a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a>
<a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a>
</pre>
    </blockquote>
    <br>
  </div></div></div>

<br>_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@lists.python.it">Python@lists.python.it</a><br>
<a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Nicola Ferrari<br>website: <a href="http://www.nicolaferrari.name">http://www.nicolaferrari.name</a><br><br>skype: nick.ferro<br><br>