简单的Android端口扫描仪

时间:2014-11-20 18:13:00

标签: java android port-scanning

我是Android的编程新手。 我想在Android中制作简单的端口扫描程序我不知道我哪里弄错了。我的扫描仪找不到任何端口...

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();
    }
}

0 个答案:

没有答案