You are not logged in.
I wrote a program today that will log into a router here at work and check if the line protocols are up and if i can see thir mac address. If i run it from the IDLE program it works fine. When i run it as just crosnet.py it runs fine but closes before i can see the output. I imagine there is some simple line that will have run and just sit? Or even better, loop back to the beginning and wait for me to give it a new number to then telnet with.
-------
#import getpass
import sys
import telnetlib
HOST = "111.111.111.111"
password = "password"
vpc = raw_input("Enter The VPC Number: ")
#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("sh int atm6/0.vpc\n")
tn.write("sh int atm6/0." + str(vpc) + "\n")
tn.write("sh arp | in " + str(vpc) + "\n")
#tn.write("exit\n")
print tn.read_all()
-----------------------------------------
Sorry the code is bad, dont know python and i was shown a outline of how to telnet and adjusted it to my needs.
Offline
while True:
and just indent everything else under it
Ends when you press ^C.
if you wish to have a way to break out of the loop, say, when you press enter at the VPC number without entering anything, add the following after your vpc input:
if not vpc:
break
which will break out of the while loop and end your program.
Last edited by buttons (2007-12-14 22:03:06)
Cthulhu For President!
Offline
In Linux how to I save it and make it excutable?
its in my home directory and i did a chmod +x crosnet.py
then opened another terminal and ran ./crosnet.py and it said
[justin@myhost ~]$ ./crosnet.py
./crosnet.py: line 1: import: command not found
./crosnet.py: line 2: import: command not found
./crosnet.py: line 6: syntax error near unexpected token `('
./crosnet.py: line 6: ` vpc = raw_input("Enter The VPC Number: ")'
any ideas?
Last edited by axion419 (2007-12-14 22:34:18)
Offline
oh. do you mean the terminal window closed when you clicked on the file to run it from python?
Try running it from the command prompt, and see if it behaves differently.
using a .pyw extension changes behavior in windows as well. It wont launch a terminal at all.
a .py extension does launch a terminal, but closes once the program finishes (you wont be able to read the output).
You could add a stanza at the end (after the print statement) to "hit any key to close", and read for any key.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
ok it works on windows as a .py, now i wish it would work in linux lol
in terminal i type
chmod +x crosnet.py
then type ./crosnet.py and i get the errors from below.
----
Offline
axion, is bash running the script? By omitting a shebang /bin/sh runs executable text files (right?)
You have to make the first line '#! /usr/bin/python'.
Offline
in linux you type "python programname.py" and that's it
Offline
ok, i can run it now python crosnet.py worked perfectly.
"You could add a stanza at the end (after the print statement) to "hit any key to close", and read for any key."
That would be great, if it would run, end the telnet, load again for next use.
how would I go about that?
You all have been a great help.
Offline