Solved

java: tcp port status remote machine

Posted on 2011-03-22
5
737 Views
Last Modified: 2012-05-11
Trying to ping remote port to see if it’s active or not. Below is an example, it only seems to check the ip address only not port.  
Thank  you

public static void main(String args[]) {

        //Creates an unresolved socket
        InetSocketAddress inetSocketAddress =
                InetSocketAddress.createUnresolved("123.123.2.3", 8181);
        
        // Gets the InetAddress
        System.out.println(inetSocketAddress.getHostName());
    }

Open in new window

0
Comment
Question by:habte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35189776
Try


InetSocketAddress inetSocketAddress =
                new InetSocketAddress("123.123.2.3", 8181);
boolean up = inetSocketAddress.getAddress().isReachable(5000);  // 5 seconds attempt

Open in new window

0
 

Author Comment

by:habte
ID: 35190591
i tried that, but i get "true" return even if the port is not available.
This only checking the ip address is reachable
E.g, I put port number 9999, and the return value was true. And when I check “telnet localhost 9999” that port is not active.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 35190689
OK. If you happen to know protocol in question, just use it on that port - that will tell you. Or simply try to open an InputStream on a Socket at that address
0
 
LVL 92

Expert Comment

by:objects
ID: 35194893
all you need is:

       InetAddress address = InetAddress.getByName("w123.123.2.3");
       boolean reachable = address.isReachable(timeout);

more info:
http://www.rgagnon.com/javadetails/java-0093.html
http://www.kodejava.org/examples/109.html
http://stackoverflow.com/questions/2448666/how-to-do-a-true-java-ping-from-windows
0
 
LVL 92

Expert Comment

by:objects
ID: 35194894
(the w is a typo :)


       InetAddress address = InetAddress.getByName("123.123.2.3");
       boolean reachable = address.isReachable(timeout);
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What's wrong with this code? 4 44
Problem to Alipay 10 91
java imports not found 4 67
Setup Eclipse for Andriod development 2 13
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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 …
Suggested Courses

740 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