// Path: library/src/main/java/com/stealthcopter/networktools/portscanning/PortScanTCP.java
// public class PortScanTCP {
// 
//     // This class is not to be instantiated
//     private PortScanTCP() {
//     }
// 
//     /**
//      * Check if a port is open with TCP
//      *
//      * @param ia            - address to scan
//      * @param portNo        - port to scan
//      * @param timeoutMillis - timeout
//      * @return - true if port is open, false if not or unknown
//      */
//     public static boolean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {
// 
//         Socket s = null;
//         try {
//             s = new Socket();
//             s.connect(new InetSocketAddress(ia, portNo), timeoutMillis);
//             return true;
//         } catch (IOException e) {
//             // Don't log anything as we are expecting a lot of these from closed ports.
//         } finally {
//             if (s != null) {
//                 try {
//                     s.close();
//                 } catch (IOException e) {
//                     e.printStackTrace();
//                 }
//             }
//         }
//         return false;
//     }
// 
// }
// 
// Path: library/src/main/java/com/stealthcopter/networktools/portscanning/PortScanUDP.java
// public class PortScanUDP {
// 
//     // This class is not to be instantiated
//     private PortScanUDP() {
//     }
// 
//     /**
//      * Check if a port is open with UDP, note that this isn't reliable
//      * as UDP will does not send ACKs
//      *
//      * @param ia            - address to scan
//      * @param portNo        - port to scan
//      * @param timeoutMillis - timeout
//      * @return - true if port is open, false if not or unknown
//      */
//     public static boolean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {
// 
//         try {
//             byte[] bytes = new byte[128];
//             DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
// 
//             DatagramSocket ds = new DatagramSocket();
//             ds.setSoTimeout(timeoutMillis);
//             ds.connect(ia, portNo);
//             ds.send(dp);
//             ds.isConnected();
//             ds.receive(dp);
//             ds.close();
// 
//         } catch (SocketTimeoutException e) {
//             return true;
//         } catch (Exception ignore) {
// 
//         }
// 
//         return false;
//     }
// 
// }


import com.stealthcopter.networktools.portscanning.PortScanTCP;
import com.stealthcopter.networktools.portscanning.PortScanUDP;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
    }

    private synchronized void portScanned(int port, boolean open) {
        if (open) {
            openPortsFound.add(port);
        }
        if (portListener != null) {
            portListener.onResult(port, open);
        }
    }

    private class PortScanRunnable implements Runnable {
        private final InetAddress address;
        private final int portNo;
        private final int timeOutMillis;
        private final int method;

        PortScanRunnable(InetAddress address, int portNo, int timeOutMillis, int method) {
            this.address = address;
            this.portNo = portNo;
            this.timeOutMillis = timeOutMillis;
            this.method = method;
        }

        @Override
        public void run() {
            if (cancelled) return;

            switch (method) {
                case METHOD_UDP:
// Path: library/src/main/java/com/stealthcopter/networktools/portscanning/PortScanTCP.java
// public class PortScanTCP {
// 
//     // This class is not to be instantiated
//     private PortScanTCP() {
//     }
// 
//     /**
//      * Check if a port is open with TCP
//      *
//      * @param ia            - address to scan
//      * @param portNo        - port to scan
//      * @param timeoutMillis - timeout
//      * @return - true if port is open, false if not or unknown
//      */
//     public static boolean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {
// 
//         Socket s = null;
//         try {
//             s = new Socket();
//             s.connect(new InetSocketAddress(ia, portNo), timeoutMillis);
//             return true;
//         } catch (IOException e) {
//             // Don't log anything as we are expecting a lot of these from closed ports.
//         } finally {
//             if (s != null) {
//                 try {
//                     s.close();
//                 } catch (IOException e) {
//                     e.printStackTrace();
//                 }
//             }
//         }
//         return false;
//     }
// 
// }
// 
// Path: library/src/main/java/com/stealthcopter/networktools/portscanning/PortScanUDP.java
// public class PortScanUDP {
// 
//     // This class is not to be instantiated
//     private PortScanUDP() {
//     }
// 
//     /**
//      * Check if a port is open with UDP, note that this isn't reliable
//      * as UDP will does not send ACKs
//      *
//      * @param ia            - address to scan
//      * @param portNo        - port to scan
//      * @param timeoutMillis - timeout
//      * @return - true if port is open, false if not or unknown
//      */
//     public static boolean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {
// 
//         try {
//             byte[] bytes = new byte[128];
//             DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
// 
//             DatagramSocket ds = new DatagramSocket();
//             ds.setSoTimeout(timeoutMillis);
//             ds.connect(ia, portNo);
//             ds.send(dp);
//             ds.isConnected();
//             ds.receive(dp);
//             ds.close();
// 
//         } catch (SocketTimeoutException e) {
//             return true;
//         } catch (Exception ignore) {
// 
//         }
// 
//         return false;
//     }
// 
// }


// Path: library/src/main/java/com/stealthcopter/networktools/PortScan.java
import com.stealthcopter.networktools.portscanning.PortScanTCP;
import com.stealthcopter.networktools.portscanning.PortScanUDP;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

    }

    private synchronized void portScanned(int port, boolean open) {
        if (open) {
            openPortsFound.add(port);
        }
        if (portListener != null) {
            portListener.onResult(port, open);
        }
    }

    private class PortScanRunnable implements Runnable {
        private final InetAddress address;
        private final int portNo;
        private final int timeOutMillis;
        private final int method;

        PortScanRunnable(InetAddress address, int portNo, int timeOutMillis, int method) {
            this.address = address;
            this.portNo = portNo;
            this.timeOutMillis = timeOutMillis;
            this.method = method;
        }

        @Override
        public void run() {
            if (cancelled) return;

            switch (method) {
                case METHOD_UDP:
                    portScanned(portNo, PortScanUDP.scanAddress(address, portNo, timeOutMillis));