Back to project page PortAuthority.
The source code is released under:
GNU General Public License
If you think the Android project PortAuthority listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.aaronjwood.portauthority.runnable; /* w w w . jav a2 s . c om*/ import android.util.Log; import com.aaronjwood.portauthority.response.HostAsyncResponse; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; public class ScanPortsRunnable implements Runnable { private static final String TAG = "ScanPortsRunnable"; private String ip; private int startPort; private int stopPort; private HostAsyncResponse delegate; public ScanPortsRunnable(String ip, int startPort, int stopPort, HostAsyncResponse delegate) { this.ip = ip; this.startPort = startPort; this.stopPort = stopPort; this.delegate = delegate; } @Override public void run() { for(int i = this.startPort; i <= this.stopPort; i++) { try { this.delegate.processFinish(0); Socket socket = new Socket(); socket.setReuseAddress(true); socket.connect(new InetSocketAddress(this.ip, i), 3500); socket.close(); this.delegate.processFinish(i); } catch(SocketException e) { Log.e(TAG, e.getMessage()); } catch(IOException e) { Log.e(TAG, e.getMessage()); } } } }