Android Network Tools


Source link: https://github.com/stealthcopter/AndroidNetworkTools

Android Network Tools

Disappointed by the lack of good network apis in android / java I developed a collection of handy networking tools for everyday android development.

  • Port Scanning
  • Subnet Device Finder (discovers devices on local network)
  • Ping
  • Wake-On-Lan
  • & More :)

General info

Sample app

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

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.stealthcopter:AndroidNetworkTools:0.3.0'
  
}

Add permission

Requires internet permission (obviously...)

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

Port Scanning

A simple java based TCP 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()

 // Synchronously
  ArrayList<Integer> 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<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]


 // Asynchronously
  SubnetDevices.fromLocalAddress().findDevices(new SubnetDevices.OnSubnetDeviceFound() {

@Override

public void onDeviceFound(Device device) {

 // Stub: Found subnet device

}

 @Override

public void onFinished(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 

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) {

...

 
}

  
}
);

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


String ipAddress = "192.168.0.1";

 String macAddress = "01:23:45:67:89:ab";

 WakeOnLan.sendWakeOnLan(ipAddress, macAddress);

Misc

Other useful methods:


String ipAddress = "192.168.0.1";

 String macAddress = 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

Resources

A highly configurable library to do loading progress with animated balls.

RxPaper is a RxJava wrapper for the cool paper library, a fast NoSQL data storage for Android that lets you save/restore Java objects by using efficient Kryo serialization and handling data structure changes automatically.

A small library to make easy connect to a REST webservice.

A way to MVVM using RxJava with new Android databinding.

Android Library to execute pieces of code that only need to run once on version updates.

Animated Expanding ListView provides a fancy animation on expanding or collapsing the content of a listview item.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes