Ping in NetRexx

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Ping in NetRexx

Robert L Hamilton
I've been trying to get a 'ping' to work in netrexx.  Found this on the www

 class PingIt
     method
  rt = Runtime.getRuntime();
--  
  ps = rt.exec("ping <127.0.0.1>");

I get this:

  === class PingIt ===
[C:\NetRexx_Java\Doodles\PingIt.nrx 7 8 2] Error: Exception 'java.io.IOException' is raised while initializing properties, but cannot be caught
Compilation of 'PingIt.nrx' failed [one error]

Does anyone have a short pinger in NetRexx??

thanks for the time and enjoy the day

BOBH

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Ping in NetRexx

rvjansen
Bob,

why don't you try:


class PingIt
  method PingIt() signals IOException
    child = Runtime.getRuntime().exec("ping 127.0.0.1");
    in = BufferedReader(InputStreamReader(child.getInputStream()))
    line = ''
    loop while line \= null
      say line
      line = in.readline()
    end
    child.waitFor()    

  method main(args=String[]) static
    PingIt()


best regards,

René.

On 23 nov 2010, at 22:39, Robert Hamilton wrote:

> I've been trying to get a 'ping' to work in netrexx.  Found this on the www
>
>  class PingIt
>      method
>   rt = Runtime.getRuntime();
> --  
>   ps = rt.exec("ping <127.0.0.1>");
>
> I get this:
>
>   === class PingIt ===
> [C:\NetRexx_Java\Doodles\PingIt.nrx 7 8 2] Error: Exception 'java.io.IOException' is raised while initializing properties, but cannot be caught
> Compilation of 'PingIt.nrx' failed [one error]
>
> Does anyone have a short pinger in NetRexx??
>
> thanks for the time and enjoy the day
>
> BOBH
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
>


_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Ping in NetRexx

alansam
Or you could try doing it the NetRexx/Java way (A simple case, I leave the implementation details to you):

/* NetRexx */

options replace format comments java crossref savelog symbols noutf8

/**
 * Ping.nrx
 *
 * @author Alan Sampson
 * @version 0.1
 */
Do
  in      = InetAddress
  host    = 'google.com'
  timeout = 100; -- milliseconds
  in      = InetAddress.getByName(host)
  ping    = boolean

  loop for 5
    ping = in.isReachable(timeout)
    if ping
    then
      Say 'Ping to' in.toString 'successful'
    else
      Say 'Ping to' in.toString 'failed'
  end
Catch uhx = UnknownHostException
  uhx.printStackTrace
Catch iox = IOException
  iox.printStackTrace
End

Alan.

PS  Caution; if you want to run successfully this under Mac OS X (and probably Linux too) you need superuser.  It appears that Java on UNIX requires root privilege to use ICMP ping function calls.  It may work on Windows.
--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: Ping in NetRexx

Thomas.Schneider.Wien
In reply to this post by Robert L Hamilton
Hello Robert,
   you might want to try SysCmd.exec in Rexx2Nrx.Rexx2RT
This should work.
Kind regards,
Thomas.
===================================================
Am 23.11.2010 22:39, schrieb Robert Hamilton:
I've been trying to get a 'ping' to work in netrexx.  Found this on the www

 class PingIt
     method
  rt = Runtime.getRuntime();
--  
  ps = rt.exec("ping <127.0.0.1>");

I get this:

  === class PingIt ===
[C:\NetRexx_Java\Doodles\PingIt.nrx 7 8 2] Error: Exception 'java.io.IOException' is raised while initializing properties, but cannot be caught
Compilation of 'PingIt.nrx' failed [one error]

Does anyone have a short pinger in NetRexx??

thanks for the time and enjoy the day

BOBH
_______________________________________________ Ibm-netrexx mailing list [hidden email]


--
Thomas Schneider Projects PP, ReyC, and LOGOS on www.KENAI.com www.thsitc.com

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Tom. (ths@db-123.com)
Reply | Threaded
Open this post in threaded view
|

Re: Ping in NetRexx

Tom Maynard
In reply to this post by alansam
On 11/23/2010 8:37 PM, Alan Sampson wrote:
Or you could try doing it the NetRexx/Java way (A simple case, I leave the implementation details to you):

/* NetRexx */

options replace format comments java crossref savelog symbols noutf8

/**
 * Ping.nrx
 *
 * @author Alan Sampson
 * @version 0.1
 */
This doesn't work for me:

C:\cygwin\home\tmaynard\NetRexx\play>java ping1
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed

C:\cygwin\home\tmaynard\NetRexx\play>ping google.com

Pinging google.com [74.125.95.106] with 32 bytes of data:

Reply from 74.125.95.106: bytes=32 time=23ms TTL=53
Reply from 74.125.95.106: bytes=32 time=22ms TTL=53
Reply from 74.125.95.106: bytes=32 time=22ms TTL=53
Reply from 74.125.95.106: bytes=32 time=21ms TTL=53

Ping statistics for 74.125.95.106:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 21ms, Maximum = 23ms, Average = 22ms

C:\cygwin\home\tmaynard\NetRexx\play>


Tom.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Ping in NetRexx

David Requena
I must admit I got surprised by this when I read your comment.

At the time I was very busy but lately I've had an assignment for a similar task and had to look further into this.

Here is what the javadoc for InetAddress.isReachable() has to say:

  "A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained"

Well, I would say that typically, the typical canonical implementation wouldn't typically do what the typical specification
says typical implementations would typically do. Hi Groucho, wherever you are :-)

Yes the windows Oracle jvm does not use icmp echo requests but tcp echo (port 7) which is closed on any host I've ever put my eyes on.

On the other hand the java API does not offer plain ICMP nor raw sockets with which you could implement it yourself.

So that's it. While on win/Oracle jvm you either use Bob's approach or leverage some jni native library like the shortpasta one which I ended using.

See http://www.shortpasta.org/ if still interested.


2010/11/24 Tom Maynard <[hidden email]>
On 11/23/2010 8:37 PM, Alan Sampson wrote:
Or you could try doing it the NetRexx/Java way (A simple case, I leave the implementation details to you):

/* NetRexx */

options replace format comments java crossref savelog symbols noutf8

/**
 * Ping.nrx
 *
 * @author Alan Sampson
 * @version 0.1
 */
This doesn't work for me:

C:\cygwin\home\tmaynard\NetRexx\play>java ping1
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed
Ping to google.com/74.125.95.106 failed

C:\cygwin\home\tmaynard\NetRexx\play>ping google.com

Pinging google.com [74.125.95.106] with 32 bytes of data:

Reply from 74.125.95.106: bytes=32 time=23ms TTL=53
Reply from 74.125.95.106: bytes=32 time=22ms TTL=53
Reply from 74.125.95.106: bytes=32 time=22ms TTL=53
Reply from 74.125.95.106: bytes=32 time=21ms TTL=53

Ping statistics for 74.125.95.106:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 21ms, Maximum = 23ms, Average = 22ms

C:\cygwin\home\tmaynard\NetRexx\play>


Tom.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]





--
Saludos / Regards,
David Requena


_______________________________________________
Ibm-netrexx mailing list
[hidden email]