Skip to content

Repository files navigation

Warning

Not under active development: This is a fork based on the Kotlin rewrite (by BharathVishal) of the original AndroidNetworkTools project by stealthcopter.

Android Network Tools image

Android ArsenalCircleCI

Disappointed by the lack of good network APIs in Android / Java I developed a collection of handy networking tools for everyday Android development.

  • Ping
  • Port Scanning
  • Subnet Device Finder (discovers devices on local network, now with NetBIOS, NSD & SSDP service scanning)
  • SSL Certificate Info Fetcher
  • Wake-On-Lan
  • & More :)

Note

com.github.fulvius31:ip-neigh-sdk30 library is used for the purpose of getting the MAC address for devices on the local network on SDK<=31.

However, this approach is blocked by the SELinux policies on newer SDK versions (>=32).

General info

The javadoc should provide all information needed to understand the methods, but if not feel free to add a issue in github and I'll address any questions! :)

Sample app

The sample app is published on Google Play & F-Droid to allow you to quickly and easier test the library. Enjoy! And please do feedback to us if your tests produce different results.

Get it on F-DroidGet it on Google Play

Usage

Add as dependency

This library is not yet released in Maven Central, until then you can add as a library module or use JitPack.io

add remote maven url

 repositories {
maven {
url "https://jitpack.io"
}
}

then add a library dependency. Remember to check for latest release here

 dependencies {
compile 'com.github.TrueMLGPro:AndroidNetworkTools:library:<commit_hash>'
}

Add permission

Requires internet permission (obviously...)

 <uses-permissionandroid:name="android.permission.INTERNET" />

Port Scanning

A simple java based TCP / UDP port scanner, fast and easy to use. By default it will try and guess the best timeout and threads to use while scanning depending on if the address looks like localhost, local network or remote. You can override these yourself by calling setNoThreads() and setTimeoutMillis()

// SynchronouslyArrayList<Integer> openPorts = PortScan.onAddress("192.168.0.1").setMethodUDP().setPort(21).doScan();
// AsynchronouslyPortScan.onAddress("192.168.0.1").setTimeOutMillis(1000).setPortsAll().setMethodTCP().doScan(newPortScan.PortListener() {
@OverridepublicvoidonResult(intportNo, booleanopen) {
if (open) // Stub: found open port
}
@OverridepublicvoidonFinished(ArrayList<Integer> openPorts) {
// Stub: Finished scanning
}
});

Subnet Devices

Finds devices that respond to ping that are on the same subnet as the current device. You can set the timeout for the ping with setTimeOutMillis() [default 2500] and the number of threads with setNoThreads() [default 255]

// AsynchronouslySubnetDevices.fromLocalAddress().findDevices(newSubnetDevices.OnSubnetDeviceFound() {
@OverridepublicvoidonDeviceFound(Devicedevice) {
// Stub: Found subnet device
}
@OverridepublicvoidonFinished(ArrayList<Device> devicesFound) {
// Stub: Finished scanning
}
});

Ping

Uses the native ping binary if available on the device (some devices come without it) and falls back to a TCP request on port 7 (echo request) if not.

// Synchronously PingResultpingResult = Ping.onAddress("192.168.0.1").setTimeOutMillis(1000).doPing();
// AsynchronouslyPing.onAddress("192.168.0.1").setTimeOutMillis(1000).setTimes(5).doPing(newPing.PingListener() {
@OverridepublicvoidonResult(PingResultpingResult) {
...
}
});

Note: If we do have to fall back to using TCP port 7 (the java way) to detect devices we will find significantly less than with the native ping binary. If this is an issue you could consider adding a ping binary to your application or device so that it is always available.

Note: If you want a more advanced portscanner you should consider compiling nmap into your project and using that instead.

Wake-On-Lan

Sends a Wake-on-Lan packet to the IP / MAC address

StringipAddress = "192.168.0.1";
StringmacAddress = "01:23:45:67:89:ab";
WakeOnLan.sendWakeOnLan(ipAddress, macAddress);

Misc

Other useful methods:

// Get a MAC Address from an IP address in the ARP CacheStringipAddress = "192.168.0.1";
StringmacAddress = ARPInfo.getMacFromArpCache(ipAddress);

Building

It's a standard gradle project.

Contributing

I welcome pull requests, issues and feedback.

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Added some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

About

Set of useful Android network tools. A Kotlin rewrite with the ip-neigh-sdk30 library for ARP lookup. Used in Wi-Fi Info 1.6+ ✨

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages