From: Alexey S. <A.S...@md...> - 2003-05-29 14:44:51
|
Hello Phillip, I am not sure whether interpreter can execute " if (expect[0] == 1):", but maybe it is better to execute the whole script as one string instead of executing it line-by-line. - Alexey. -- { http://trelony.cjb.net/ } Alexey N. Solofnenko Pleasant Hill, CA (GMT-8 usually) -----Original Message----- From: Sweeney, Phillip (Phil), ALABS [mailto:phi...@at...] Sent: Tuesday, May 27, 2003 10:50 AM To: jyt...@li... Subject: [Jython-dev] jython/yelnetlib Hello - I am new to jython and think that it is quite cool - - - Howerver - It seem s t be missing what i need - & I think I might just be looking in the wrong place... I am trying to write a quick program that will go and telnet to a unix box, login and see what group membership a user has. I also have wider ranging needs to be able to telnet from java. So I looked at using java sockets for telnet - but this is much more complicated than writing your own client AND server sockets and then sending text back and forth - which i have done successfully in the past. Telnet requires much more than simple sockets. So I tried to write a python program to do the telnetting using Jython 2.1. I successfully wrote a python program to telnet to a machine and determine user groups - all should be great!!! Now - I try to glue the whole thing together and Jython will not run the script! Included in the lib folder of jython is the telnetlib.py, but i cannot call it from the java program... Do I need to do anything else before running this java/jython code? Is there a better way to do this? Thanks - ********** Code Below ********** import org.python.util.PythonInterpreter; import org.python.core.*; public class UnixLogin_Python { public static void main(String []args) throws PyException { PythonInterpreter interp = new PythonInterpreter(); System.out.println("Starting Python Unix Login Script..."); interp.exec("import sys"); interp.exec("import telnetlib"); interp.exec("#HOST = \"192.168.100.111\""); interp.exec("HOST = \"135.16.126.84\""); interp.exec("user = \"crflog\""); interp.exec("password = \"crflog\""); interp.exec("x=10"); interp.exec("i=0"); interp.exec("while i<x:"); interp.exec(" tn = telnetlib.Telnet(HOST)"); interp.exec(" tn.set_debuglevel(10)"); interp.exec(" tn.read_until(\"ogin: \")"); interp.exec(" tn.write(user + \"\\n\")"); interp.exec(" if password:"); interp.exec(" tn.read_until(\"assword: \")"); interp.exec(" tn.write(password + \"\\n\")"); interp.exec(" login_results = \"\""); interp.exec(" expect = tn.expect(([\"ast login\", \"incorrect\"]))"); interp.exec(" print expect[0]"); interp.exec(" print expect"); interp.exec(" if (expect[0] == 0):"); interp.exec(" print \"successful login\""); interp.exec(" tn.write(\"exit\\n\")"); interp.exec(" login_results = tn.read_all()"); interp.exec(" tn.close()"); interp.exec(" if (expect[0] == 1):"); interp.exec(" print \"unsuccessful login\""); interp.exec(" tn.write(\"\\x04\")"); interp.exec(" tn.write(\"\\x04\")"); interp.exec(" #login_results = tn.read_all()"); interp.exec(" tn.close()"); interp.exec(" #login_results = tn.read_until(\"$\", 20)"); interp.exec(" #tn.write(\"ls\\n\")"); interp.exec(" #tn.write(\"exit\\n\")"); interp.exec(" #tn.write(\"\\x04\")"); interp.exec(" ##tn.write(\"\\n\")"); interp.exec(" ##tn.write(\"\\n\")"); interp.exec(" ##tn.write(\"\\n\")"); interp.exec(" #tn.write(\"exit\\n\")"); interp.exec(" #login_results = tn.read_all()"); interp.exec(" #tn.close()"); interp.exec(" print \"LOGIN_RESULTS****:\""); interp.exec(" print login_results;"); interp.exec(" #print tn.read_all()"); interp.exec(" i=i+1"); } } *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Phillip Sweeney AT&T Labs 200 Laurel Ave - D52A05 Middletown, NJ 07748 phi...@at... phi...@ya... (732) 420-2501 - office (203) 820-4666 - cell *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ------------------------------------------------------- This SF.net email is sponsored by: eBay Get office equipment for less on eBay! http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 _______________________________________________ Jython-dev mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-dev |