[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

java telnet app

I need to write a java app that will telnet to a unix server run some commands and grab the output of that command.
can some one give info or point me to some links about sun's telnet class ?

Thanks
0
nramesh30
Asked:
nramesh30
  • 7
  • 6
1 Solution
 
gadioCommented:
There are free implementations of telnet that you can use. Here is one of them:
http://www.first.gmd.de/persons/leo/java/Telnet
0
 
gadioCommented:
Opps! This was not meant to be a 'proposed answer'. You can reject it if its not an answer for you.
:-)
0
 
nramesh30Author Commented:
How and where would I specify the user name , password and the command to run ?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
nramesh30Author Commented:
okay . sorry . i got it . its in the wrapper class
0
 
nramesh30Author Commented:
I'm unable to javac compile telnetwrapper.java file . it gives me lot of class telnetio not found error.
I'am very new to java
0
 
gadioCommented:
What errors do you get? Please paste it I'll tell you what the problems are.
0
 
nramesh30Author Commented:
I'am able to compile now. But my app will not know the prompt ahead of time . So I tried to use send() mixed with wait() calls . but it does not work . This is what I tried.
telnet.wait("login:");
   telnet.send("joe" + "\r");
   telnet.wait("Password");
   telnet.send("joeopass" + "\r");

Now what should be my next call ? what do i wait for ?
0
 
gadioCommented:
Here is a sequance I used and its working for me:


  public static void main(String args[])
  {
    try {
      tio.connect("one.machine.ip.address.com");
      wait("login:");
      send("gadio\r");
      wait("Password:");
      send("my_real_password\r");
      wait(">");  //my prompt
      send("touch /tmp/THIS_WAS_AN_APPLET\r");
      wait(">"); //my prompt
      tio.disconnect();
    } catch(IOException e) { e.printStackTrace(); }
  }
}


Hope this helps you!
0
 
nramesh30Author Commented:
    wait(">"); //my prompt

Here's where I have the problem. U know ur prompt ahead of time (>). I cannot make that generalization. The code has to be able to handle any prompt.
Because users of the app might have different prompts in their environment.


     
0
 
gadioCommented:
Not a big problem I think. You can set the prompt as you wish as the first operation of the telnet.
Are these users going to have the same shell (sh / csh / tcsh)? If not - the problem is slightly more complicated...
In any case you will need to have a "smart connection"  that finds which enviroment the telnet is connected to, and then configure whatever is necesarry.
0
 
gadioCommented:
More problems??
0
 
nramesh30Author Commented:
Thanks . it works fine.
0
 
gadioCommented:
So I will answer.
This time - don't ACCEPT the answer...
:-)
0
 
jscapeCommented:
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now