Login into a remote host and test one ip whether its pinging or not.

Hello Friends
I need to login into a remote host. From that remote host i need to test one ip that whether its is pinging or not.
For that i have written one code snippet its working fine when that ip is pinging.
But it is hanging when that ip is not pinging properly.
I could not read the output while not pinging.
For making telnet connection to the remote host, i am using jcsh.jar
Any body know the solution for that please help me.see below my code.
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class Exec{
  public static void main(String[] arg){
    try{
      JSch jsch=new JSch(); 
      String temp = "";
      String host=null;
      if(arg.length>0){
        host=arg[0];
      else{
        host=JOptionPane.showInputDialog("Enter username@hostname",System.getProperty("user.name")+"@localhost");
      String user=host.substring(0, host.indexOf('@'));
      host=host.substring(host.indexOf('@')+1);
      Session session=jsch.getSession(user, host, 22);
      // username and password will be given via UserInfo interface.
      UserInfo ui=new MyUserInfo();
      session.setUserInfo(ui);
      session.connect();
      String command=JOptionPane.showInputDialog("Enter command",
                                                 "ping ");
      Channel channel=session.openChannel("exec");
      ((ChannelExec)channel).setCommand(command);
      channel.setInputStream(null);
      ((ChannelExec)channel).setErrStream(System.err);
      BufferedWriter stdOut = new BufferedWriter(new OutputStreamWriter(channel.getOutputStream()));
      channel.connect();
      int count = 0;
      int count1 = 0;
      while(true) {
      if((temp = stdInput.readLine()) != null || (temp = stdInput.readLine()).compareTo("") != 0 ) {
           System.out.println("NOT NULL OUTPUT");
           while ((temp = stdInput.readLine()) != null) {
           System.out.println(">"+temp);
            if(temp.indexOf("64 bytes from") == 0) {
               if(count++ > 4)
                    System.out.println("Ping Okay");
                    channel.disconnect();
                    break;
        try{Thread.sleep(1000);}catch(Exception ee){}
      else
           System.out.println(">"+temp);
           count1++;
           if(count1>10)
                System.out.println("Ping is not okay.");
                break;
           else {
                System.out.println("Trying...");
//                continue;
           try{Thread.sleep(1000);}catch(Exception ee){}
      if(channel.isClosed()){
          System.out.println("exit-status: "+channel.getExitStatus());
          break;
      channel.disconnect();
      session.disconnect();
    catch(Exception e){
      System.out.println(e);
  public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{
    public String getPassword(){ return passwd; }
    public boolean promptYesNo(String str){
      Object[] options={ "yes", "no" };
      int foo=JOptionPane.showOptionDialog(null,
             str,
             "Warning",
             JOptionPane.DEFAULT_OPTION,
             JOptionPane.WARNING_MESSAGE,
             null, options, options[0]);
       return foo==0;
    String passwd;
    JTextField passwordField=(JTextField)new JPasswordField(20);
    public String getPassphrase(){ return null; }
    public boolean promptPassphrase(String message){ return true; }
    public boolean promptPassword(String message){
      Object[] ob={passwordField};
      int result=
        JOptionPane.showConfirmDialog(null, ob, message,
                                      JOptionPane.OK_CANCEL_OPTION);
      if(result==JOptionPane.OK_OPTION){
         passwd=passwordField.getText();
        return true;
      else{
        return false;
    public void showMessage(String message){
      JOptionPane.showMessageDialog(null, message);
    final GridBagConstraints gbc =
      new GridBagConstraints(0,0,1,1,1,1,
                             GridBagConstraints.NORTHWEST,
                             GridBagConstraints.NONE,
                             new Insets(0,0,0,0),0,0);
    private Container panel;
    public String[] promptKeyboardInteractive(String destination,
                                              String name,
                                              String instruction,
                                              String[] prompt,
                                              boolean[] echo){
      panel = new JPanel();
      panel.setLayout(new GridBagLayout());
      gbc.weightx = 1.0;
      gbc.gridwidth = GridBagConstraints.REMAINDER;
      gbc.gridx = 0;
      panel.add(new JLabel(instruction), gbc);
      gbc.gridy++;
      gbc.gridwidth = GridBagConstraints.RELATIVE;
      JTextField[] texts=new JTextField[prompt.length];
      for(int i=0; i<prompt.length; i++){
        gbc.fill = GridBagConstraints.NONE;
        gbc.gridx = 0;
        gbc.weightx = 1;
        panel.add(new JLabel(prompt),gbc);
gbc.gridx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weighty = 1;
if(echo[i]){
texts[i]=new JTextField(20);
else{
texts[i]=new JPasswordField(20);
panel.add(texts[i], gbc);
gbc.gridy++;
if(JOptionPane.showConfirmDialog(null, panel,
destination+": "+name,
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE)
==JOptionPane.OK_OPTION){
String[] response=new String[prompt.length];
for(int i=0; i<prompt.length; i++){
response[i]=texts[i].getText();
     return response;
else{
return null; // cancel

Do a Google search for "java ftp client". There are some existing packages that you can use.

Similar Messages

  • IPhoto: I was downloading photos from my iPhone every day during my holidays and suddenly one day: the following file could not be imported unrecognized format. And it's still same iPhone 4S and same format JPEG

    iPhoto: I was downloading photos from my iPhone every day during my holidays and suddenly one day: the following file could not be imported unrecognized format. And it's still same iPhone 4S and same format JPEG

    What version of iPhoto?
    As a Test:
    Hold down the option (or alt) key and launch iPhoto. From the resulting menu select 'Create Library'
    Import a few pics into this new, blank library. Is the Problem repeated there?
    Post back with the result.

  • I am not able to login to my facebook account and error message reads "This web site does not supply ownership information." Please help

    I am not able to login to my facebook account and error message reads "This web site does not supply ownership information." Please help
    only title bar opens and nothing else....please help

    Normally, when you connect via http, the browser doesn't check for site identity, so I don't understand what's happening there.
    Do you have any security-related add-ons that force popular sites to use a secure connection, or claim to provide anonymous browsing?
    Were you making the connection on your own network or on a public network (e.g., school, coffee shop)? If it was a public network, maybe the error indicates that your traffic was being intercepted???
    Without hands on, this is a tough one to diagnose.

  • IPod updates 2 touch with the new software, and from the update they are not connected with Time phase. They appear calling but never they enter the calls. I make calls with other users and if one connects but in these two not from the update

    iPod updates 2 touch with the new software, and from the update they are not connected with Time phase. They appear calling but never they enter the calls. I make calls with other users and if one connects but in these two not from the update

    I use Firefox 95% of the time, and there's no problem with flash content (and I'm still at .55 - downloaded .64 last week but I haven't got round to making the change yet). At the rate they've been changing it recently it may well be out of date already .
    I've been trying it in Safari, too with no problems apart from You Tube, but that's because I'm blocking Google cookies.
    One thought does occur - if your Flash preferences are set to block all Local Storage, it may be that the problem site is trying to use Flash cookies (LSOs). I had this problem recently with the BBC iPlayer streaming content. Little Snitch notified an attempt to connect to a new URL - emp.bbci.co.uk.
    If I disallowed it, no streaming; when I allowed the connection, it still wouldn't stream, so I did a bit of digging and came to the conclusion that it was trying to set a Flash cookie. When I unblocked, lo and behold - streaming resumed as normal.
    I now have LSOs blocked in a more subtle way that lets the site think it's being set (but it ain't) and the streaming still works.
    As for permissions repair - always repair from local; the permissions on the original disc will have been superceded by updates and new installations of Apple software.
    DU needs to be reading the packages on the HD, not the (now out of date) install disc.
    The recurring repair messages are normal and don't mean anything's wrong. As long as the final message is 'repair complete' there's no need to dwell on it.
    http://support.apple.com/kb/TS1448 (for Leopard and Snow Leopard - Lion no doubt has it's own set).

  • When I try to download a pdf file it turns into a .do file and can't be opened by my Samsung note 3

    When I try to download a pdf file it turns into a .do file and can't be opened by my Samsung note 3. Once downloaded the file can't be found in any part of the device memory and can't be opened by the browser mozilla.

    Hello there,
    Have you checked if your PDF Plugins are updated? https://www.mozilla.org/en-US/plugincheck/
    For more options: https://support.mozilla.org/en-US/kb/view-pdf-files-firefox-without-downloading-them
    Hope this helps!

  • I received and email from Apple Customer Support that my Id has been stolen and that I am to sign into the link provided and update by changing password. I am not certain that the email came from Apple.

    I received and email from Apple Customer Support that my Id has been stolen and that I am to sign into the link provided and update by changing password. I am not certain that the email came from Apple.

    It did not come from Apple. Do not click on the link and do not supply your password. It is a scam. You can report the phishing email to Apple here:
    Phishing & Other Suspicious Emails
    Once you have done so, delete it.
    Cheers,
    GB

  • Hi I've pulled my sticker off my itunes redeem code and I'm wanting to know hw I can retrieve my money or atleast have it transferred into my itunes account , and I've tried apple support it's not helping at all

    Hi I've pulled my sticker off my itunes redeem code and I'm wanting to know hw I can retrieve my money or atleast have it transferred into my itunes account , and I've tried apple support it's not helping at all

    If you haven't remove the code from the card then you should be able to redeem it onto your account e.g. via the Redeem button under Quick Links on the right-hand side of the iTunes store homepage on your computer's iTunes, or via the bottom of the Music tab if using an iOS device
    Redeeming a card : Redeeming iTunes Gift Cards and content codes

  • I bought a new 5s and its front and back camera are not working, showing black image. My phone is IOS 7 updated, and some one insisted that its is software updation problem, and can be resolved by updating to IOS 8. Kindly suggest.

    I bought a new 5s and its front and back camera are not working, showing black image. My phone is IOS 7.1.2 updated, and some one insisted that its is software updation problem, and can be resolved by updating to IOS 8. Kindly suggest.

    I have the same issue on my iPhone 5s
    I've closed the app and re-booted the phone several times but it did not resolve the issue.
    Upgrading to iOS 8.0.2 did not resolve it either.
    Erasing the iPhone and restoring from a backup did not resolve it.
    I'm not sure what else to do.

  • I bought a new iPhone 5s and its front and back camera are not working, showing black image. My phone is IOS 7 updated, and some one insisted that its is software updation problem, and can be resolved by updating to IOS 8. Kindly suggest on this. Wil

    I bought a new iPhone 5s and its front and back camera are not working, showing black image. My phone is IOS 7 updated, and some one insisted that its is software updation problem, and can be resolved by updating to IOS 8. Kindly suggest on this. Will this resolve my issue?

    any advise..?

  • Telneting to a remote host and executing unix shell script

    I am using VPN.I want to telnet to a remote server and execute some script there and show it the output in my front end..is it easily possible thru java..i know it can be easily done thru Python...can anyone let me knw if this can ve achieved properly thru java..thnx plz let me knw ASAP.

    Yes surely I have wriiten the code..
    I have first used a Socket to connect to teh host at port 23.
    Then i am using outstream to give the user and passwd .. but in my Inputstream i am getting some vague outputs (some symbols..$,%,etc..) This is the code for ur reference....
    import java.net.*;
    import java.io.*;
    class Telclient {
    public static void main(String args[]) {
    int c;
    try{
    Socket s=new Socket("abc.net",23);
    InputStream in=s.getInputStream();
    OutputStream out=out.getoutputStream();
    String str="user" + "\n" + "password" + "\n";
    byte buf[]=str.getBytes();
    out.write(buf);
    while((c=in.read()) != -1) {
    System.out.println((char)c);
    s.close();
    Please help with teh code , bcoz its not really working..Need urgent helpI also used TelnetClient from jakarta , but failing to understand
    how to use those classes to use..can anyone show me an example...

  • I have an iphone4, and suddenly one day my factime app does not work anymore!! How do I get it to work again, Please?

    I am using an iphone4. Suddenly one day my factime app does not work anymore!! How do I get it to work again, Could someone please me?

    Try a reset or restart of the device. If it still does not appear on any of the home screens and cannot be found in a spotlight search, restore the device.

  • My pad is asking for a passcode and the one I thought it was is not working and it disables the ipad. Does anyone know how to fix this problem ? Thanks

    Hi, I am looking for assistance on how to reset the passcode on my ipad. It is asking for a passcode & then I enter what I thought it was and it doesn't accept & disables the ipad for 15 mins. Any guidance would be greatly appreciated ast the call centre is currently closed. Thanks  Peter

    If You Are Locked Out, Have Forgotten Your Passcode, or Just Need to Restore Your Device
    1. iTunes 10 for Mac- Update and restore software on iPod, iPhone, or iPad
    2. iPhone, iPad, iPod touch: Wrong passcode results in red disabled screen
    3. iOS- Understanding passcodes
    4. What to Do If You've Forgotten Your iPhone's Passcode
    5. How to Recover Forgotten iPhone Restrictions Passcode | The iPhone and iPad
         If you have forgotten your Restrictions code, then follow the instructions
         below but DO NOT restore any previous backup. If you do then you will
         simply be restoring the old Restrictions code you have forgotten. This
         same warning applies if you need to restore a clean system.
    A Complete Guide to Restore or Recover Your iDevice (if You Forget Your Passcode)
    If you need to restore your device or ff you cannot remember the passcode, then you will need to restore your device using the computer with which you last synced it. This allows you to reset your passcode and re-sync the data from the device (or restore from a backup). If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present. Refer to Updating and restoring iPhone, iPad and iPod touch software.
    Try restoring the iOS device if backing up and erasing all content and settings doesn't resolve the issue. Using iTunes to restore iOS devices is part of standard isolation troubleshooting. Restoring your device will delete all data and content, including songs, videos, contacts, photos, and calendar information, and will restore all settings to their factory condition.
    Before restoring your iOS device, Apple recommends that you either sync with iTunes to transfer any purchases you have made, or back up new data (data acquired after your last sync). If you have movie rentals on the device, see iTunes Store movie rental usage rights in the United States before restoring.
    Follow these steps to restore your device:
         1. Verify that you are using the latest version of iTunes before attempting to update.
         2. Connect your device to your computer.
         3. Select your iPhone, iPad, or iPod touch when it appears in iTunes under Devices.
         4. Select the Summary tab.
         5. Select the Restore option.
         6. When prompted to back up your settings before restoring, select the
              Back Up option. If you have just backed up the device, it is not necessary
              to create another.
         7. Select the Restore option when iTunes prompts you (as long as you've backed up,
             you should not have to worry about restoring your iOS device).
         8. When the restore process has completed, the device restarts and displays the Apple
             logo while starting up:
               After a restore, the iOS device displays the "Connect to iTunes" screen. For updating
              to iOS 5 or later, follow the steps in the iOS Setup Assistant. For earlier versions of
              iOS, keep your device connected until the "Connect to iTunes" screen goes away or
              you see "iPhone is activated."
         9. The final step is to restore your device from a previous backup. If you do not have a
              backup to restore or have forgotten your restrictions passcode, then restore as New.
    If you are restoring to fix a forgotten Restrictions Code or as a New device, then skip Step 9 and restore as New.

  • Someone used my Game Center account to login into Clash of Clans and now he has my account. Help me please

    Someone connected to my Clash of clans account. Help me please.

    Have you given your information to anyone?   Family, friend?
    Did you have another device with Game Center on it?   Did you give a new owner of a device any passwords?
    Do you share apple account with a family member?
    Do you have a rescue email set up in your Apple account, with security questions? 
    I suggest you set up a new email account, write everything down and keep it in a safe place.
    New email account and password. Not so easy that it can be hacked.
    In your iTunes account on the computer. Login and change security questions, password and rescue email.
    Again, make sure your password is not easy to guess.   Same with security questions.
    Write it all down and keep it somewhere safe.
    I recommend a password keeper called Enpass.   You can store 10 cards with user names, passwords, notes and account numbers in the free version.
    Then you only have to remember one complicated password to open Enpass and retrieve your information.
    If all else fails, contact apple support.

  • Can I log out the game centre on my pad and let someone into there game centre and play one of there games

    Hi all can I log out of game centre on my pad and let someone else log in to play one of there games

    ``````Apparently it is in 'setttings' now.
    Tried logging out from there. may need a couple of times. it seems to auto 'relogged' back in.
    a little annoying

  • Can I host a Windows Phone VHS on a remote host and have Visual Studio debug on it?

    As per the title really, is it possible to have an instance of the windows phone emulator running on our Hyper-V dev cluster and then have development machines use it for debugging?
    Our development machines are also virtualised, and as such we can't host the windows emulator on them.
    Thanks. 

    Hi Mandeep,
    Since this issue is related to the specific Windows Phone apps, to help you resolve this issue as soon as possible, you could post this issue to the Windows Phone forum here:
    http://social.msdn.microsoft.com/Forums/wpapps/en-us/home?category=wpapps&filter=alltypes&sort=lastpostdesc
    I think you would get dedicated support from the Windows Phone expert. Thanks for your understanding.
    Best Regards, 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Upgrade Stopped - Unable to logon to system

    Windows 2003 Server 64bit , Sql 2005, Upgrade erp2004 -> erp2005. Upgrade has stopped in phase startsap_nbas, and although the system will start you are unable to logon due to the error "error when initialising the work area SYST". On investigation t

  • Report Engine SDK sample code questions

    Hello, I've been able to view a boxi report in an iframe via the Enterprise SDK by modifying the sample code in the HowToViewWebiReports_VB example. I'm not totally happy with the way that's working, so I'm looking at using the Report Engine SDK, alt

  • Application hangs while trying to create a socket

    Hello, We have a third party application that makes HTTP connections using a old version of HTTPClient. Recently we have run into problems where the application hangs as one thread seems to hang while trying to create a socket (thread dumps show the

  • SPP: Error while saving result in Interactive Forecasting

    Hi SCM experts, While saving interactive forecasting but (using "SAVE") system is raising error exceptions. Source Determination Error: Source Loc. 121P Dest. Loc. 122P Product 0000000000000000000000000004018632005101 Message no. /SAPAPO/PALG015 Furt

  • Restrict PO creation as material blck for quality reason in other plant

    Hi QM Experts, one material (say MAT-1) in maintained in  two plants (Say- X & Y). qm in procurement active in material for both the plants. created two Q-info records with material MAT-1, vendor ( Say- V-1). one info record for plant X & other for p