Blog

Android Network Tools Open Source Library

Following my work on Portdroid (Network analysis android app), I decided to release some of the code I used to write it as an open source library on github. All contributions and suggestions are welcome!

The library offers a few very simple to use interfaces which encapsulate common networking operations that are more difficult that needed on android. Below are a couple examples, see the readme for more indepth examples, and the sample app for implementations.

Pinging

     // Synchronously 
     PingResult pingResult = Ping.onAddress("192.168.0.1").setTimeOutMillis(1000).doPing();

     // Asynchronously
     Ping.onAddress("192.168.0.1").setTimeOutMillis(1000).setTimes(5).doPing(new Ping.PingListener() {
      @Override
      public void onResult(PingResult pingResult) {
        ...
      }
    });

Port Scanning

    // Synchronously 
    ArrayList openPorts = PortScan.onAddress("192.168.0.1").setPort(21).doScan();

    // Asynchronously
    PortScan.onAddress("192.168.0.1").setTimeOutMillis(1000).setPortsAll().doScan(new PortScan.PortListener() {
      @Override
      public void onResult(int portNo, boolean open) {
        if (open) // Stub: found open port
      }

      @Override
      public void onFinished(ArrayList openPorts) {
    // Stub: finished scanning
      }
    });

Leave a Comment

Your email address will not be published. Required fields are marked *