Telnet Program

Hi all,
I am trying to write a very simple program to connect to another PC on port number 23 (TELNET). After I launch my program, I get the PC's login prompt, and my program tries to login as "root" and waits for the password prompt, however the program displays the letter "r" instead of "password prompt". I am not sure if the other PC receives the "root" as user name??????. Following is my coding any help is greatly appreciated in advance.
import java.io.*;
import java.net.*;
public class ListenCommands{
private static byte[] ba ;
private static boolean running = true;
private static int arraySize = 200;
public static void main (String args[]) {
ba = new byte[arraySize];
if (args.length < 1)
System.out.println(
"raidCommands usage: java raidCommands <IP addr> ");
return;
InetAddress mIP = null;
InetAddress IP = null;
Socket sock = null;
InputStream is = null;
OutputStream os = null;
String strCommand ;
boolean socketStatus = true;
try {
mIP = InetAddress.getByName(args[0]);
} catch(UnknownHostException e) {
System.out.println("InetAddress failure:\n\r" + e);
try{
IP = InetAddress.getLocalHost();
}catch(UnknownHostException e){
System.out.println("Can not obtain host IP Address:\r\n" + e);
try {
sock = new Socket(mIP, 23,IP,23);
//sock = new Socket(mIP, 30001);
} catch(Exception e) {
System.out.println("TCP raidCommands make socket:\n\r" + e);
try {
os = sock.getOutputStream();
} catch(IOException e) {
System.out.println("TCP raidCommands get output stream:\n\r" + e);
try {
is = sock.getInputStream();
} catch(IOException e) {
System.out.println("TCP raidCommands get input stream:\n\r" + e);
try{
while(is.available() == 0 )
System.out.println("Waiting for login prompt...");
Thread.sleep(1000);
}catch(IOException e){
}catch(InterruptedException f){
resetArray();
try {
is.read(ba);
} catch(IOException e) {
System.out.println("TCP raidCommands read:\n\r" + e);
System.out.println("sending root to Tini");
strCommand = "root\r\n";
System.out.println("Entered UserName...." + strCommand);
try{
os.write(strCommand.getBytes());
}catch(IOException e) {
System.out.println("Can not write to output stream\n" + e);
try{
while(is.available() == 0 )
System.out.println("Waiting for password Prompt...");
Thread.sleep(1000);
}catch(IOException e){
}catch(InterruptedException f){
resetArray();
try{
is.read(ba);
}catch(IOException e) {
System.out.println("TCP raidCommands read:\n\r" + e);
System.out.println("Recived from Other computer......" + new String(ba));
try{
sock.close();
}catch(IOException e){
System.out.println("IOException closing socket:\r\n:" + e);
} // End of main
public static void resetArray()
for ( int i =0; i < ba.length;i++)
ba =0;
Thanks,
Mehran

Thanks for your responces.Could some one tell me what is the tag ? and how I could use it? or perhaps give a direction on where to read about it?
Thanks again....

Similar Messages

  • Telnet program with NI-Layer for SAPRouter

    Hello everybody,
    I want to administrate our SAP WebAS Java Servers via telnet, because it's scripting capable (see https://wwwn.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/s-u/saptelnetscript.article)
    I want to do it via SAPRouter, so I can use the SNC functionality for encryption (telnet passwords won't be transmitted in cleartext).
    I know that the SAP Support has a telnet program that is capable to connect through a SAPRouter. I think it was recompiled with NI-Layer functionality.
    Is there a way to get this telnet program from elsewhere ?
    I have done some tests with the netcat (linux Swiss Army Knife) tool where I have used the description of the connection establishment from the sap.help.com.
    But I could only initiate a NATIVE ROUTING connection without getting a telnet session.
    So I ask you, if someone can help me to solve my problem
    Carsten Promper
    Systems Administrator

    Hi Wahoo,
    I need to write a LabVIEW program ... Thank you very much for any help
    All you wrote between is just the description of your "needs"...
    How can we help, when you don't ask specific questions?
    - When you want to learn LabVIEW: there are online courses available on www.NI.com.
    - You will find a lot of examples in your LabVIEW installation: just look for the "Help" menu...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Telnet Program Help

    I would like to write a program that does the following:
    1. Telnet to a linux machine.
    2. Execute an "ls" command.
    3. Return the output of the "ls" command.
    4. Parse the output for file names and display in a JTable.
    I found a sample program from the Java Forum to Telnet to the machine, but I don't know how to execute a command over telnet and get the output of the command. Can you please help? Thanks.

    Peter,
    I have the following that "works". But I have 2 minor problems left:
    1. How can I detect that the command had finished running? Currently, it's stuck in the while loop in getOutput().
    2. Currently I'm writing the command output to a file. Is there a way to put it into a buffer and return it from the getOutput() function?
    import java.net.*;
    import java.io.*;
    * This class implements a Telnet session.
    public class VTelnet2
         Socket sock;
         PrintStream     os;
         InputStream     in;
         OutputStream    ot;
         BufferedReader br;
         BufferedWriter bw;
         public VTelnet2(String host, int port)
              try
                   sock = new Socket(host, port);
                   //for input
                   os = new PrintStream(sock.getOutputStream());
                   //for output
                   ot = sock.getOutputStream();
                   in = sock.getInputStream();
                   br = new BufferedReader(new InputStreamReader(in));
                   bw = new BufferedWriter ( new FileWriter ( new File ("c:\\dummy123.txt")));
              catch(IOException e)
                   System.out.println(e);
                   return;
         public void test ()
              sendCommand( "ls" );
              getOutput ();
              try
                   bw.close ();
              catch(Exception e)
                   e.printStackTrace();
         public void sendCommand ( String command )
              //send
              os.print(command);
              os.print("\r\n");
              os.flush();
         public void getOutput ()
              String line;
              int    i;
              try
                   while(true)
                        i = br.read();
                        bw.write((char)i);
                        bw.flush();
              catch(IOException e)
                   throw new RuntimeException(e.getMessage());
         private void tel_net(int i1, int i2)
              int i = i1;
              if (i == 253)
                   i = i2;
                   if (i == 1)  wont(i);
                   else if (i == 24) wont(i);
                   else if (i == 31) wont(i);
                   else if (i == 35) wont(i);
                   else if (i == 36) wont(i);
                   else if (i == 39) wont(i);
         private void wont(int i)
              try
                     ot.write(255);
                   ot.write(252);
                   ot.write(i);
              catch (IOException e)
                   System.out.println(e);
         public static void main(String args[])
              String host = "10.10.111.222";
              int    port = 23;
              VTelnet2 foo = new VTelnet2(host, port);
              foo.test();
    }

  • Help debugging an internet toolkit/telnet program

    I'm using internet toolkit in order to program a telnet session for an intelligent power control unit. My program appears to be working...the data LED flashes when I send info to the instrument, but it doesn't respond properly (IE the power won't be turned off/on). Is there anyway to debug this error by seeing a replica of a telnet window and see what exactly is being entered? (the commands are very picky...any spaces before or after command will throw it off). I have attatched the application if it is of any use to anyone. Right now, only case 3 and stop have the code i'm going to insert. the @@@@ is the pword being sent to the unit in order to start the session.
    Attachments:
    Example_IPC_2.vi ‏142 KB

    Sorry, I can answer re: "seeing a replica of a telnet window and see what exactly is being entered? "
    Is your "byte written 2" correct?
    If not, it may be due to you send ASCII characters and not hex. Right-click on your string constant and select "hex display" to enter the values as hex.
    Do you have any indication the password is working correctly i.e. does a led light to indicate logged on?
    Don't have that toolkit installed on this machine so that's as far as I can go for now.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Entering data into a mySQL database for use with my JDBC program

    does any know what i type on telnet to get mySQL to work on windows 2000?
    i read check your isp for what to type in for this line, but i use IIS
    www24:mywww/devshed# mysql -u devshed -p
    and what do i put for
    login: devshed
    Password: ********
    it says check with isp on that one too
    i am trying to insert records, and make columns, is there an easier way to do this?
    thanks,
    Pearl
    Beginning MySQL Tutorial
    By W.J. Gilmore
    April 03, 1999
    Part 1: At First Glance
    MySQL is most commonly entered through telnet. (A nice Telnet program, Easyterm, can be found at http://www.arachnoid.com) Once the telnet connection to the web server has been accomplished, a second command provides access to the MySQL server. The procedure to make these connection is as follows:
    1. Connect to telnet. This involves the insertion of the given ISP username and password.
    --------------------------------------------------------------------------------login: devshed
    Password: ********
    Last login: Wed Aug 12 09:49:14 from 195.103.124.222
    Copyright 1992, 1993, 1994, 1995, 1996 Berkeley Software Design, Inc.
    Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
    The Regents of the University of California. All rights reserved.
    BSDI BSD/OS 2.1 Kernel #12: Mon Feb 23 13:46:27 EST 1998
    You have new mail.
    www24:mywww/devshed#
    2. Connect to MySQL. This involves the insertion of the username and password given specifically for MySQL use. This information has probably been provided to you at your request to the ISP provider.
    --------------------------------------------------------------------------------www24:mywww/devshed# mysql -u devshed -p--------------------------------------------------------------------------------
    Syntax: mysql -h hostname -u username -p[password]
    Or
    mysql -h hostname -u username --password=password
    The user will then be prompted for a password, as prompted by -p.
    --------------------------------------------------------------------------------Enter password: *******--------------------------------------------------------------------------------
    Assuming MySQL has been correctly installed and configured, the user will see output similiar to the following:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 49 to server version: 3.21.23-beta-log
    Type 'help' for help.
    mysql>
    (Note: If an error message pertaining to "Access denied" is the result of connection attempts, you should consult the MySQL documentation included with the software, the MySQL mailing list found at http://www.mysql.com, as well as your ISP provider. These resources will aid greatly in resolving these problems.)
    Once connected to the database, we are free to execute the various commands of the MySQL language. However before we are able to modify the database, we must first connect to it, via the command:
    --------------------------------------------------------------------------------mysql> use devshed;
    Result:
    --------------------------------------------------------------------------------Database changed
    Mysql>
    You now are connected to the database. Note that the command was followed by a semi-colon (;). Almost all commands in MySQL are followed by a semi-colon.
    At the disposition are a number of administrative commands. These commands can be viewed simply by typing help, \h or ? at the command line:
    --------------------------------------------------------------------------------mysql> help
    help (\h) Display this text
    ? (\h) Synonym for `help'
    clear (\c) Clear command
    connect (\r) Reconnect to the server. Optional arguments are db and host
    edit (\e) Edit command with $EDITOR
    exit (\) Exit mysql. Same as quit
    go (\g) Send command to mysql server
    print (\p) print current command
    quit (\q) Quit mysql
    rehash (\#) Rebuild completion hash
    status (\s) Get status information from the server
    use (\u) Use another database. Takes database name as argument
    Connection id: 49 (Can be used with mysqladmin kill)
    mysql>

    Let's make this simple:
    a) Your book seems to assume you're doing development remotely.
    b) You are not doing development remotely.
    c) Therefore, you shouldn't follow every step listed in your book (i.e. ignore the stuff about Telnet).
    Assuming you installed mySQL in the standard location, you can use this batch file to start mySQL on your machine:
    @echo on
    cd c:\mysql\bin
    mysqld
    @echo off
    cls
    Use this batch file to shut down mySQL:
    @echo on
    cd c:\mysql\bin
    mysqladmin shutdown
    @echo off
    cls
    You can play around without a login or password in development. For a production environment, you're going to need to set up users and grant permissions.
    Spend some time reading the mySQL documentation.

  • How to connect iseries green screen from java program

    how to connect iseries green screen from java program to get the data in the DB files ,here the DB is DB2/400

    Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
    import java.io.*;
    import java.net.*;
    public class AutoTelnet {
         private static Socket s;
         public static void main(String[] args) throws Exception {
              Thread t = new Thread() {
                   @Override public void run() {
                        try {
                             s = new ServerSocket(5555).accept();
                        } catch (IOException ex) {
                             ex.printStackTrace();
              t.start();
              Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
              t.join();
              PrintStream ps = new PrintStream(s.getOutputStream());
              ps.println("Screen will be cleared in 5 seconds");
              ps.println("5");
              Thread.sleep(1000);
              ps.println("4");
              Thread.sleep(1000);
              ps.println("3");
              Thread.sleep(1000);
              ps.println("2");
              Thread.sleep(1000);
              ps.println("1");
              Thread.sleep(1000);
              ps.println("\u001b[2J");
              Thread.sleep(5000);
    }

  • LMS 4.0.1 - telnet from topology services map

    On a LMS 4.0.1 :
    I want to know what is the right way to change the telnet program on the campus mgr map (topology services map), when right-clicking a device icon and selecting telnet.
    I would like to use a tool of mine, and not to launch a telnet command from the IE browser.
    I changed the default telnet of Windows in the registry, but the program is still launched as a telnet URL in the browser and this is not what I would like to do.
    If anybody has any clue ? thanx
    Marc - CCIE 2700

    With LMS 4.0.1 I use Java 1.6.
    The Java Plug-in control panel is different (no way to configure the DCMSSH parameter).
    And this parameter is used with LMS 2.5 or 2.6 as per the example in the link you provided.
    are you certain it applies to LMS4.0.1 as well ?
    Additionaly, I don't want to use SSH, but only Telnet.
    Thnak you
    Marc.

  • Capture TelNet Screen From Remote Server.....

    Iam using Sun Solaris having an ERP package, which requires its screens & its datas to be captured from a remote server. Presently Iam able to capture the screen & its datas by using telnet and logging on to the remore server. Now my requirement is this - is it possible to capture the same datas and screen through Java in any way. Any ideas, suggestions, opinions what ever is welcome. I would like to hear from u.....

    Hi, my opinion is to write a telnet program in Java that is able to capture the returning message from the remote server. Here is an example of Telnet via Java. Hope it helps :)
    http://www-rohan.sdsu.edu/faculty/vinge/courses/spring00/cs580/notes/javanet/javanet.html

  • Opening Telnet with a web browser

    Hi,
    I don't know if I'm posting this thread in the right forum, I hope I am. I want to have a web page and, when the user selects a link, I want a telnet prompt to be opened in the user's computer. Not a embeded one, but the actual telnet program they use on their computers. Does anyone know if there's a way to do it using servlets, JSP, Java...?
    I know this does it, but it will open the prompt in the server.
    Runtime.getRuntime().exec("cmd /c telnet 201.78.23.122 1234");Is there an equivalent I can use to do it on the client's side?
    Thank you

    You could try using a telnet URL. Something like this:
    telnet://201.78.23.122:1234
    Of course, the user's browser needs to be configured correctly to call the telnet client. In Windows, try AbsoluteTelnet. It configures your browser for you so these types of telnet links will work properly. SSH links too:
    ssh://201.78.23.122:1234
    Brian Pence
    Celestial Software
    AbsoluteTelnet (for telnet and ssh)

  • Telnet GUI client giving problems for one userid.

    Hi,
    I have written a GUI program to get userid and password to connect to a Telnet session. The purpose of the program is just to check if the user is a valid user and start another application if the user is a valid user. This application works well and is installed for manay users at my work place. But, this program doesn't work well only for one user. That user tried to use this program by changing is password. He tried to login using this GUI in other terminals. Only this user is having problems logging in in any terminal. But, he is able to open a telnet session without any problems if he doesn't use the GUI. I tried to print the characters that are returned by the server. But, it prints all the characters without any problem. The application hangs at the point, when it has to read the $ prompt after logging in. I also, checked if this user has been set with any other properties for his userid than other users. But, he is having the same privelages like all other users.
    Any help in fixing this problem is appreciated.
    Thanks in advance.

    You need to be more specific about what your program does, for us to suggest some troubleshooting techniques.
    One possibility:
    Your program takes the user's id and password, and if it can authenticate the user, it launches the telnet program (at which point, your user needs to authenticate himself again at telnet's login prompt. In other words, your program provides access to telnet.
    If that is the case, then your user may have changed his password on the remote host, but neglected to change his password on the GUI. I doubt this is the case, but the point I wanted to make is perhaps your GUI is having problems authenticating the user.
    Check to make sure the string the user typed matches the string you have on file. (See below for more on this.)
    The other possibility is:
    Your GUI takes the user's id and password, launches a telnet session, and tries to log in the user via proxy. If it works, the telnet session
    is returned back to the user. If it fails, an appropriate error message is returned. Your program is essentially a front end to telnet.
    If that is the case, then you're likely to have a problem transmitting the password string. Perhaps the user's new password has a character Java and telnet interpret differently.
    First thing to check is literally have your GUI output the string to the telnet session. Don't ask the user to type it in, just ask him what it is. If the password is "fido" (hypothetically), then have your GUI do the equivalent of out.write( "fido" );
    If it bombs, you know you can't transmit that particular string, and the short term solution is to change the password again. If it works, have the user type in the password, but instead of sending it to telnet, just system.out.println( inputtedPassword ); instead. See if Java does any unintentional formatting when reading it in.
    In other words, treat input and output as two seperate cases, and test accordingly.
    When you think about it, that particular password is the key. In fact, if you told us what the password is (don't tell us who you are or where you're connecting from), some Java Guru might see it and say "Oh, you can't do a double backslash like that!"
    Anyways, I'm sure you've solved the problem, I just posted this explaination for the benefit of others who are curious about how to troubleshoot something like this.

  • How can I send an F5 thru a telnet session?

    I have to logon to a remote machine with a telnet session. To do this manually, I have to hit F5 to bring up the login prompt after the telnet session is established. I can establish the connection with LabVIEW, but how can I send the F5?

    Telnet is essentially an ASCII-only protocol. There's no "F5" in ASCII, so you're probably supposed to send some sequence of ASCII codes to make it work.
    Typically, text-based telnet programs emulate various kinds of physical terminals, such as DEC's warhorse "vt52" and "vt100" terminals, or the old ADM-3A. Those terminals sometimes had special keys that could send a sequence of commands. For example, I think the vt100 had an "F5" key that sent Escape (a byte containing decimal 27) followed by the letters "Ot". (I am looking at a UNIX box with an /etc/termcap entry for a vt100, and interpreting what it says. I'm not an expert at UNIX /etc/termcap entries, so I may be misreading it.)
    Anyway, you need to find out what kind of terminal this remote machine
    is expecting you to use. This will tell you what string to send for an F5 key.
    I hope this helps.

  • Telnet to call java server functions

    Hi, I've got the following problem:
    I have a server written in java. I would like to controll that java server by telnetting into it and then issue text commands to it.
    How do I do it? Something like this?
    1. Telnet into the computer that must have a telnet server running.
    2. Start the java server "controll" program with >java serverController ...
    3. Typing commands and read the printouts
    Do I miss something?
    Gil

    Thanks Kaj,
    So you mean that I can just set up a server, and then anyone can use the "telnet" protocoll to connect to it?
    Anyway, I need to use an existing telnet program since I might need to extend to ssh etc in the future. So what I need is a running telnet server which I telnet into, and then from that telnet session make "calls" to the server program
    Joey: The server program IS developed by me.
    I am trying to set up a telnet server on my windows. But it just gives me a stupid text echo window. I want the "text" I write to be forwarded to the command (or the chell in unix). Is it just a matter of the telnet server program? In that case, do you know a free, good, telnet server program from where I can forward the "text" to the command?
    Gil

  • How to clear the DOS screen through java program

    how to clear the DOS screen through java program

    Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
    import java.io.*;
    import java.net.*;
    public class AutoTelnet {
         private static Socket s;
         public static void main(String[] args) throws Exception {
              Thread t = new Thread() {
                   @Override public void run() {
                        try {
                             s = new ServerSocket(5555).accept();
                        } catch (IOException ex) {
                             ex.printStackTrace();
              t.start();
              Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
              t.join();
              PrintStream ps = new PrintStream(s.getOutputStream());
              ps.println("Screen will be cleared in 5 seconds");
              ps.println("5");
              Thread.sleep(1000);
              ps.println("4");
              Thread.sleep(1000);
              ps.println("3");
              Thread.sleep(1000);
              ps.println("2");
              Thread.sleep(1000);
              ps.println("1");
              Thread.sleep(1000);
              ps.println("\u001b[2J");
              Thread.sleep(5000);
    }

  • Telnet Print Protocol

    We are using telnet program to access a site where we grab some reports. In tiger, the telnet session was able to print the reports to our local printer. However, after the upgrade to Leopard, we cannot do that anymore.
    The documentation for the telneted site states that the telnet program should support Telnet Print Protocol. Did anyone encounter this issue before and was able to solve it?

    We are using telnet program to access a site where we grab some reports. In tiger, the telnet session was able to print the reports to our local printer. However, after the upgrade to Leopard, we cannot do that anymore.
    The documentation for the telneted site states that the telnet program should support Telnet Print Protocol. Did anyone encounter this issue before and was able to solve it?

  • Display Error while installing Oracle 11g R2 in RHEL 5 !!!

    hi
    I am trying to install Oracle 11g R2 in RHEL 5. When i run ./runInstaller it didnt pass one checking..which showed an error:
    >>> Could not execute auto check for display colors using command /usr/X11R6/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<
    i run xhost +
    it showed:
    [oracle@localhost database]$ xhost +
    Xlib: connection to ":0.0" refused by server
    Xlib: No protocol specified
    xhost: unable to open display ":0.0"
    i exported the DISPLAY too..its workedd..but still its showing the same error..
    here iam trying to install the oracle 11g on RHEL 5 in a common PC...not using any Vmware or Virtual box and not trying to install it from remote PC. But still iam facing the same error.
    Kindly help me to resolve this issue.
    Shiyas M

    Hi;
    Firstly you are working on server or you use some telnet program like putty? If you are working on server than issue is:
    as root
    xhost +
    than run xlock and be sure u can see clock
    than su - oracle
    xhost + once more than try to run ./runInstaller
    If you connect server remotly than i use vncwier
    1. as root run export DISPLAY=hostname or IP:1.0
    2. xhost +
    3. run xclock and see u see it on vncviwer
    4. su - oracle
    5. run export DISPLAY again
    6. xhost
    7. /runInstaller
    Regard
    Helios

Maybe you are looking for

  • Wired Windows XP Printing Problem to AEBS. HELP!!!!!

    I have been trying to figure this out for the past two days. Im basically about to rip my hair out. I have an old AEBS (the saucer one) with the 5.7 firmware, with an HP Office Jet J5780 connected. I have 2 Macs, both running 10.5.2 connected wireles

  • What are record groups for?

    hi, Could anybody tell me what is the main purpose of creating record groups whith statements like: create_group_from_query, populate_group, ... Every time we want to access any records we can use blocks which are based on tables or views which are i

  • CSS Background Shifts Down

    So, i am working on my school's website in my Web Development Course, and everything seems to be going fine. I have enctountered a problem, i have a divider holding a table that is our navigation bar, and below it the content of the site. When it is

  • [CS3][JS] Batch

    Hello, I've found my first response. Now, How do you specify fileNaming whithout extension ? In UI i'm a value "Sans/None" but not by script. #target photoshop app.bringToFront(); displayDialogs = DialogModes.NO; //Tableau contenant les images var do

  • Trying to return my unused BT Hub - hopeless situa...

    Left BT last week as I was at the end of my 18 month contract - had a letter asking me to return my hub - but no prepaid envelope to do so. Contacted BT who say that since I am no longer a BT customer they refuse to provide the returns envelope - and