File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes IPAddress and Port Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "IPAddress and Port" Watch "IPAddress and Port" New topic
Author

IPAddress and Port

rama krishnan
Ranch Hand

Joined: Mar 14, 2008
Posts: 68
how to ping the IPAddress and Port using java by pressing JButton
and also I don't know how to read the port from system
[ August 21, 2008: Message edited by: muthurama krishnan ]

MRK
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Even though you may be starting a process from a JButton, the real question involves ping/networking, so I'm moving it to the "Sockets and Network Protocols" forum. If you're really asking about "ping" (ICMP) - there's an easy way to do it in JDK 1.5+. However, "ping" doesn't have a concept of ports, so I'm not sure what the "I don't know how to read ports from the system" part means.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
The problem with trying to use a standard ping program to see if a machine will respond is that many machines and networks simply drop these sorts of requests so no response could mean various things.

There are other ways to find out if a machine is running at an IP address. NMAP, Nessus can certainly do it, I have found that if NMAP or Nessus can't return any results at all, nothing will.

The most straightforward way in Java to test whether a port is open(which I am assuming that is what you meant) is to try to connect to port number with a TCP socket and also try sending a UDP datagram to it and see what if anything happens. To control this via a JButton, simply start the object that runs this simple port scanner with the button's listener.

You could also write a program to send a single ACK, SYN, or FIN packet to all possible ports and see if any are open, though if they are all stealthed you won't learn anything useful. A traceroute program that is a little sneaky and uses UDP, ACK, SYN, or FIN sometimes gets through networks that drop ICMP traffic. They won't respond to ICMP based traceroute but are happy to send back a time exceeded ICMP message for TCP or UDP traffic.

These last two can't be done with only the Java API, you need to either write your own JNI wrapper around libpcap or use existing ones like Jpcap and jpcap.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
T.A. Nguyen
Ranch Hand

Joined: Sep 02, 2008
Posts: 36

If you have an IP and a Port, then just open a socket connection and check the status/exception of that connection to determine.


enjoy!


T.A. Nguyen
http://ta.cnci.org
http://www.linkedin.com/in/nguyenta
 
Consider Paul's rocket mass heater.
 
subject: IPAddress and Port
 
Similar Threads
finding IP address
Socket Connection Problem
about 192.168.0.202 importan
pls help :mutiple ipaddress?
Problem with Retriving mails from INBOX