Win a copy of hapi.js in Action this week in the HTML, CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Telnet execution using Java

 
Nizamuddin Shaikh
Ranch Hand
Posts: 34
1
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone!

I am trying to execute a statement to retrieve some information from remote Linux server using telnet command. I am able to connect to remote server but unable to pass next statement to retrieve information.
I am posting my code (after replacing sensitive data)




However the response from the remote server should be "I am fine"
output.JPG
[Thumbnail for output.JPG]
This is the output I am getting, However the connection is still open
 
Nizamuddin Shaikh
Ranch Hand
Posts: 34
1
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short! Can I combine two commands command1 and command2 to get the output?
 
Nizamuddin Shaikh
Ranch Hand
Posts: 34
1
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I combine command1 and command2 by using echo "How are you \n" | telnet localhost 7777. I am getting "Connection closed by Foreign host"
 
Tim Moores
Bartender
Posts: 3199
54
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does JSch support the Telnet protocol? I thought it was an SSH library.

The Apache Commons Net library includes a Telnet client.
 
Nizamuddin Shaikh
Ranch Hand
Posts: 34
1
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it does support telnet.
 
Nizamuddin Shaikh
Ranch Hand
Posts: 34
1
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to fix my problem. Here's the solution that worked for me. command ="{ echo 'How are you'; sleep 1; } | telnet localhost 7777"
 
Nizamuddin Shaikh
Ranch Hand
Posts: 34
1
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:
The Apache Commons Net library includes a Telnet client.


I will study about Apache Commons Net library. Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!