Solved

How to I run a small Telnet script in Linux from Java and get back the result?

Posted on 2008-10-30
4
1,202 Views
Last Modified: 2012-08-13
Thank you
0
Comment
Question by:kerzner
  • 2
4 Comments
 
LVL 10

Expert Comment

by:kyleb84
ID: 22845973
You want to connect to somewhere via Telnet, but the Telnet client is in Java?
You want this to be a non-interactive procedure?

You'll need a java Telnet client, there's plenty around - then you need to gut it and take out the Telnet protocol handling.

Then you'll need to add on to that class providing automated read/write functions for your application.

It's a fair bit of work but possible.

For a start, here's a Telnet/SSH client in java, source code available.

http://javassh.org/space/start

0
 
LVL 12

Accepted Solution

by:
basav_com earned 500 total points
ID: 22876504
You have to use expectJ here.
http://expectj.sourceforge.net/

More info:
ExpectJ is a Java implementation of the Unix expect utility. ExpectJ provides a Unix expect like support to write Java Programs that communicate with other programs and perform some operation on them.
If you are not familiar with working of the Unix expect utility, please refer to man page of expect. Usage of ExpectJ requires a proper understanding of the Unix expect utility.
For example using ExpectJ you can write a Java program that telnets to a host machine and deletes the contents of /tmp. This program when configured as a cron job will always keep the /tmp under the specified limit.
0
 
LVL 1

Author Comment

by:kerzner
ID: 22876906
kyleb84, the reason I am going this way is because Telnet, when I use it standalone, did work properly. My Java code did not. So I plan to wrap the use of Telnet. I will try your approach if ExpectJ does not work out.
0
 
LVL 1

Author Comment

by:kerzner
ID: 22876918
basav_com,

it sounds like what I need, and I will use it first thing tonight. I vaguely remember having used Unix expect with good results.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now