Αρπαγή εξόδου της εντολής telnet

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Αρπαγή εξόδου της εντολής telnet

Marios Zindilis-2
Γειά χαρά.

Όταν εκτελείται η εντολή telnet, η συσκευή-στόχος δείχνει μια προτροπή
(prompt). Για παράδειγμα, το Access Point μου λέει κάτι σαν:

[marios@czar ~]$ telnet 192.168.1.1
DD-WRT v24-sp2 voip (c) 2010 NewMedia-NET GmbH
Username:

ενώ το modem μου λέει κάτι σαν:

[mariosz@czar ~]$ telnet 192.168.2.1
Modem Brand 5.4.3.2.1
Login:

Θέλω να "αρπάξω" την έξοδο της εντολής telnet σε μια μεταβλήτη ενός script
σε Bash ή σε Expect, και να την χρησιμοποιήσω αργότερα. Έχω δοκιμάσει
αρκετά πράγματα σε Bash και Expect, χωρίς να κάνω αυτό που θέλω. Έχει
κανείς καμμιά καλύτερη ιδέα;

Αν υπάρχει και πρόταση που συμπεριλαμβάνει άλλη γλώσσα (Python, PHP, Perl ή
άλλη) είναι και πάλι αποδεκτή.

--
Marios Zindilis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-gr/attachments/20120123/ae13f885/attachment.html>
--
Ubuntu-gr mailing list
[hidden email]

If you do not want to receive any more messages from the ubuntu-gr mailing list, please follow this link and choose unsubscribe:
https://lists.ubuntu.com/mailman/listinfo/ubuntu-gr
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Αρπαγή εξόδου της εντολής telnet

Johny Stilianakos
dokimase na to apo8ikeuseis se ena arxeio keimenou gia px kai meta na
diabaseis tin seira pou 8eleis!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-gr/attachments/20120123/07056380/attachment.html>
--
Ubuntu-gr mailing list
[hidden email]

If you do not want to receive any more messages from the ubuntu-gr mailing list, please follow this link and choose unsubscribe:
https://lists.ubuntu.com/mailman/listinfo/ubuntu-gr
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Αρπαγή εξόδου της εντολής telnet

Savvas Radevic
In reply to this post by Marios Zindilis-2
Δηλαδή χρειάζεσαι μόνο αυτό το.. telnet prompt;

#!/usr/bin/python
from subprocess import *
command = ["/usr/bin/telnet", "192.168.1.1"]
p = Popen(command, stdin=PIPE, stderr=PIPE, stdout=PIPE)
# Grabs the stdout and kills the process
out = p.communicate()[0]
print(p.wait())
msg = "Command {0}\nOutput: {1}"
print(msg.format(" ".join(command), out))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-gr/attachments/20120123/3fc3e7f0/attachment.html>
--
Ubuntu-gr mailing list
[hidden email]

If you do not want to receive any more messages from the ubuntu-gr mailing list, please follow this link and choose unsubscribe:
https://lists.ubuntu.com/mailman/listinfo/ubuntu-gr
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Αρπαγή εξόδου της εντολής telnet

Marios Zindilis-2
Μάλιστα, αυτό ακριβώς, έξοχα γιατρέ μου! :)

Στο σενάριο εντολών που έφτιαξα, τελικά το υλοποίησα με το NetCat, το
οποίο ανοίγει συνδέσεις δικτύου σε οποιαδήποτε θύρα, δηλαδή αντί για:

telnet 192.168.1.1

κάνεις:

nc 192.168.1.1 23

Όπου 23 είναι η θύρα του telnet (από προεπιλογή). Το NetCat έχει τη
διαφορά ότι βγάζει το αποτέλεσμα στην πρότυπη έξοδο (stdout) άρα μπορεί
κανείς να το «αρπάξει» σε μια μεταβλητή του Bash ή να το ανακατευθύνει
σε ένα αρχείο κειμένου.

Πληροφοριακά, ο σκοπός του σεναρίου εντολών είναι να εκτελεί την ίδια
εργασία (για παράδειγμα να λαμβάνει αντίγραφο ασφαλείας) από συσκευές
δικτύου οι οποίες είναι διαφορετική μάρκα η κάθε μια, άρα και έχουν
διαφορετικές εντολές για το ίδιο πράγμα. Αξιολογώντας την προτροπή της
κάθε κάθε συσκευής στο telnet, το σενάριο αποφασίζει ποιές εντολές θα
εκτελέσει σε κάθε συσκευή.

On 01/23/2012 05:10 PM, Savvas Radevic wrote:

> Δηλαδή χρειάζεσαι μόνο αυτό το.. telnet prompt;
>
> #!/usr/bin/python
> from subprocess import *
> command = ["/usr/bin/telnet", "192.168.1.1"]
> p = Popen(command, stdin=PIPE, stderr=PIPE, stdout=PIPE)
> # Grabs the stdout and kills the process
> out = p.communicate()[0]
> print(p.wait())
> msg = "Command {0}\nOutput: {1}"
> print(msg.format(" ".join(command), out))
>


--
Marios Zindilis

--
Ubuntu-gr mailing list
[hidden email]

If you do not want to receive any more messages from the ubuntu-gr mailing list, please follow this link and choose unsubscribe:
https://lists.ubuntu.com/mailman/listinfo/ubuntu-gr
Loading...