• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Search | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

Java Ping

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More

View previous topic :: View next topic  
Author Message
[[Merlin]]
Just Arrived
Just Arrived


Joined: 16 Dec 2003
Posts: 3
Location: United Kingdom

Offline

PostPosted: Mon Aug 30, 2004 10:47 pm    Post subject: Java Ping Reply with quote

Hi all,

After doing a little research on google its seems that the standard Java networking libraries do not support ICMP ping. I have read this is because ICMP packets can only be created by a socket of the SOCK_RAW type. So does anyone know of alternatives that would give me this functionality. Presently I'm aware that the Runtime class could be used something like this:

Code:
Process prog = Runtime.getRuntime().exec("ping.exe IP_ADDRESS");

BufferedReader br = new BufferedReader(new InputStreamReader(prog.getInputStream()));

while((inputLine = br.readLine()) != null)
{
   System.out.println(inputLine);
           
}


Yet this really walks over the fact that Java is platform independent by running a windows program, thefore could some sort of open source packet driver be the answer? I would really appreciate if someone good point me in the right direction or just explain why Sun haven't added this functionality or whether it's in the pipeline.
Back to top
View user's profile Send private message
Dunceor
Just Arrived
Just Arrived


Joined: 05 Sep 2003
Posts: 4
Location: Sweden

Offline

PostPosted: Mon Aug 30, 2004 11:15 pm    Post subject: Reply with quote

I don't know in java but if you are using C there is a great lib called libnet which makes it dead easy to create ICMP packets.
Libnet: http://libnet.sourceforge.net/
Back to top
View user's profile Send private message Visit poster's website
[[Merlin]]
Just Arrived
Just Arrived


Joined: 16 Dec 2003
Posts: 3
Location: United Kingdom

Offline

PostPosted: Tue Aug 31, 2004 1:47 am    Post subject: Reply with quote

Thanks for the quick reply Dunceor. But unfortunately I'm only familiar with Java because I've only recently started to program. But perhaps by the sounds of it I should learn another language like C if I want this sort of functionality. Unless someone else has some thoughts on the matter.
Back to top
View user's profile Send private message
el-half
Just Arrived
Just Arrived


Joined: 01 Jan 2004
Posts: 0
Location: Cyberspace

Offline

PostPosted: Tue Aug 31, 2004 8:51 am    Post subject: Reply with quote

Maybe this can be useful: http://sourceforge.net/projects/jpcap

I've never used it so I don't know what its possibilities are but it might be what you are looking for.
Back to top
View user's profile Send private message Visit poster's website
sequru
Just Arrived
Just Arrived


Joined: 31 Jul 2004
Posts: 0


Offline

PostPosted: Tue Aug 31, 2004 9:34 am    Post subject: Reply with quote

Hi,

If you want to use ping in order to find out whether the host alive or not, then you can use Sockets. Here is what I have found from http://www.torsten-horn.de/techdocs/java-net.htm

Code:

import java.net.*;
 
  public class PingSimple
  {
    public static void main( String[] args )
    {
      InetAddress iaHost = null;
      int         iPort  = 80;
      System.out.println( "\nUsage: java PingSimple host [port] \n" +
                          " e.g.: java PingSimple www.Torsten-Horn.de \n" +
                          "   or: java PingSimple 1.2.3.4 80 \n" );
      try
      {
        if( 0 >= args.length )
          throw new Exception( "Parameter missing!" );
        iaHost = InetAddress.getByName( args[0] );
        if( 1 < args.length )
          iPort = Integer.parseInt( args[1] );
        long tm = System.currentTimeMillis();
        Socket so = new Socket( iaHost, iPort );
        so.close();
        tm = System.currentTimeMillis() - tm;
        System.out.println( "Connection ok (port " + iPort + ", time = " + tm + " ms). \n" +
                            "Host Address = " + iaHost.getHostAddress() + "\n" +
                            "Host Name    = " + iaHost.getHostName() );
        System.exit( 0 );
      } catch( Exception ex )
      {
        System.out.println( "Error: " + ex.getMessage() );
        System.exit( 1 );
      }
    }
  }

Back to top
View user's profile Send private message
[[Merlin]]
Just Arrived
Just Arrived


Joined: 16 Dec 2003
Posts: 3
Location: United Kingdom

Offline

PostPosted: Wed Sep 01, 2004 12:39 am    Post subject: Reply with quote

Hi,

Firstly thanks to both el-half and sequru for your input as it gives me two futher avenues to explore. Although after reading sequru's link its does confirm my first post that ICMP ping is not directly implemented in Java. So does anybody know why it has not been included, is it someone to do with how the virtual machine is structured or just Sun bureaucracy.
Back to top
View user's profile Send private message
el-half
Just Arrived
Just Arrived


Joined: 01 Jan 2004
Posts: 0
Location: Cyberspace

Offline

PostPosted: Wed Sep 01, 2004 6:13 pm    Post subject: Reply with quote

The Java platform is secure so they didn't implement raw sockets. At least, that is what I think is the reason.
Back to top
View user's profile Send private message Visit poster's website
eobyn
Just Arrived
Just Arrived


Joined: 02 Sep 2004
Posts: 0


Offline

PostPosted: Fri Sep 03, 2004 6:55 pm    Post subject: Reply with quote

You can use a C library to ping and create a JNI native method map between C and JAVA. I don't think there is a way to create ICMP packets included in java API, not sure though.
Back to top
View user's profile Send private message
yazid
Just Arrived
Just Arrived


Joined: 13 Oct 2004
Posts: 0


Offline

PostPosted: Wed Oct 13, 2004 9:55 pm    Post subject: java ping Reply with quote

hi, I had the same problem and then i found this site which answers your question. http://www.geocities.com/SiliconValley/Bit/5716/ping/index_eng.html
the implentation is for Windows.
Good luck! Smile
Back to top
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Community Area

Log in | Register