I am new in programming for Android. I want make simply port scanner in Android i dont know where i made mistake. My scanner dont find any port...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread t=new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
startScan();
}
});
t.start();
}
private void startScan() {
InetAddress inetAddress;
try {
byte[] addr = {(byte) 127, (byte)0, 0, 1};
inetAddress = InetAddress.getByAddress(addr);
for (int port = 1; port <= 65000; port++) {
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress(inetAddress,port),1500);
final String text = "Is listening on port " + port;
Log.e("RESULT",text);
socket.close();
} catch (IOException e) {
}
}
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}