• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IPAddress and Port

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 36
Eclipse IDE Java ME Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic