Results 1 to 20 of 20
  1. #1
    prabhurangan is offline Member
    Join Date
    May 2008
    Posts
    69
    Rep Power
    0

    Default Java program to ping remote machine using IP address..?

    Dear Members,

    I have to ping a remote machine, which is used as a server for my support project. If the server is down it takes more time to load the application. So i have to redirect to error page 'Support site is down for maintanence'. How to know the status of remote machine, whether it is up or down.


    Please let me know the solutions for this issue.

    Regards,
    Prabhu.

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    Look at InetAddress.isReachable(). This performs the ping function and returns true if the ping was successful.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  4. #4
    sourabh is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi I wants to ping a remote server. As i am behind the proxy i am not able to ping it .Is there any way to bind proxy with InetAddress. This is always giving False result.

    My code snippet is:

    InetAddress address = InetAddress.getByName("www.google.com");
    boolean chkConnection = address.isReachable(1000);

    Please help

    Regards
    Sourabh

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    sourabh is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi
    I am behind a proxy server for Vlan. I can't access the internet directly. I access via proxy setting.

  7. #7
    sourabh is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    Please help me in how to bind proxy with inetAddress.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually you cannot do this through a proxy server. I'll explain why I ask that question from you.

    To ping to the outside host from your LAN, it's required to ICMP protocol request complete. Proxies are not allowed that. If you are using MS Proxy then it's allowed only passe UDP and TCP. We can control those things within the proxy server as you wish at the time of build it.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  10. #10
    Biboo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Hi Everybody, Im trying to use the InetAddress.isReachable(). but its not known in my JDK, it is showing me an error , isReachable() methode is not recognized.
    Please tell me how to fix this, i really need the solution

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    It's better, if you could show something over here that what you've done. So it's easy to comment on you.

  13. #13
    Biboo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    hi, thanks for replying me.. here is the example code:

    Java Code:
    import java.io.IOException;
    import java.net.InetAddress;
    
    public class IPTest {
     
        public static void main(String[] args) {
             try {
                InetAddress adr = InetAddress.getByName("10.252.11.112");
                System.out.println("Host is reachable: "+adr.isReachable(3000));
            }catch (IOException e) {
                e.printStackTrace();
            }         
        }
    }
    the isReachable() methode not recognized in my code , i have tried many examples.. still the same problem.
    Last edited by Eranga; 10-13-2010 at 07:13 AM. Reason: code tags added

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Hi Biboo, please use code tags next time when you are posting code segments. Sometimes, not like in a small code segment, it's really hard to read unformated codes. It's a good practice, use them. :)

    If you don't know how to do it, check my forum signature. You can find a relevant link for that.

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Regarding your question, what you mean by method not recognized in your code? Can you elaborate it.

  16. #16
    Biboo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    hi Eranga,

    when i generate the code it says that isReachable() is not reconized , it is like not existing in the library.
    you got me now??

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  18. #18
    Biboo is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    Of course i did :P
    i just cant understand...

  19. #19
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  20. #20
    rajatkumarv is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Thumbs up Re: Java program to ping remote machine using IP address..?

    hey every one there is only one mistake that the agr you give in getByName() is add not name

    try this:-

    import java.io.*;
    import java.net.*;

    public class NetScanner2
    {
    byte a[] = {10,17,1,(byte)136};

    public NetScanner2()
    {
    try
    {
    System.out.println(InetAddress.getByAddress(a).isR eachable(10000));
    }catch(Exception e)
    {}
    }

    public static void main(String []args)
    {
    new NetScanner2();

    }

    }

Similar Threads

  1. Ping in Java
    By VeasMKII in forum New To Java
    Replies: 7
    Last Post: 10-14-2012, 10:51 PM
  2. Replies: 10
    Last Post: 02-28-2012, 09:44 PM
  3. Replies: 1
    Last Post: 02-15-2008, 05:07 PM
  4. Getting address of Local Machine
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-24-2007, 08:38 PM
  5. how to load a file in remote machine
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •