Skip to content

Commit b595e3c

Browse files
committed
Added subnet device scanning, updated build versions and readme.
1 parent 36b6a3b commit b595e3c

File tree

6 files changed

+66
-55
lines changed

6 files changed

+66
-55
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ android {
3030
applicationId "com.stealthcotper.networktools"
3131
minSdkVersion minSdkVer
3232
targetSdkVersion targetSdkVer
33-
versionCode 9
34-
versionName "0.1.14"
33+
versionCode 10
34+
versionName "0.3.0"
3535
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3636
}
3737

app/src/main/java/com/stealthcotper/networktools/MainActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.stealthcopter.networktools.WakeOnLan;
2222
import com.stealthcopter.networktools.ping.PingResult;
2323
import com.stealthcopter.networktools.ping.PingStats;
24-
import com.stealthcopter.networktools.subnet.SubnetInfo;
24+
import com.stealthcopter.networktools.subnet.Device;
2525

2626
import java.io.IOException;
2727
import java.net.InetAddress;
@@ -225,12 +225,12 @@ private void findSubnetDevices() {
225225

226226
SubnetDevices.fromLocalAddress().findDevices(new SubnetDevices.OnSubnetDeviceFound() {
227227
@Override
228-
public void onDeviceFound(SubnetInfo subnetInfo) {
229-
appendResultsText("Device: " + subnetInfo.ip+" "+subnetInfo.hostname);
228+
public void onDeviceFound(Device device) {
229+
appendResultsText("Device: " + device.ip+" "+ device.hostname);
230230
}
231231

232232
@Override
233-
public void onFinished(ArrayList<SubnetInfo> devicesFound) {
233+
public void onFinished(ArrayList<Device> devicesFound) {
234234
float timeTaken = (System.currentTimeMillis() - startTimeMillis)/1000.0f;
235235
appendResultsText("Finished "+timeTaken+" s");
236236
}

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion minSdkVer
99
targetSdkVersion targetSdkVer
10-
versionCode 7
11-
versionName "0.2.34"
10+
versionCode 10
11+
versionName "0.3.0"
1212
}
1313
buildTypes {
1414
release {

library/src/main/java/com/stealthcopter/networktools/SubnetDevices.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import android.support.annotation.NonNull;
44

55
import com.stealthcopter.networktools.ping.PingResult;
6-
import com.stealthcopter.networktools.subnet.SubnetInfo;
6+
import com.stealthcopter.networktools.subnet.Device;
77

88
import java.net.InetAddress;
99
import java.net.UnknownHostException;
@@ -19,16 +19,16 @@ public class SubnetDevices {
1919
private int noThreads = 255;
2020

2121
private ArrayList<String> addresses;
22-
private ArrayList<SubnetInfo> devicesFound;
22+
private ArrayList<Device> devicesFound;
2323
private OnSubnetDeviceFound listener;
2424

2525
// This class is not to be instantiated
2626
private SubnetDevices() {
2727
}
2828

2929
public interface OnSubnetDeviceFound {
30-
void onDeviceFound(SubnetInfo subnetInfo);
31-
void onFinished(ArrayList<SubnetInfo> devicesFound);
30+
void onDeviceFound(Device device);
31+
void onFinished(ArrayList<Device> devicesFound);
3232
}
3333

3434
/**
@@ -118,9 +118,9 @@ public void findDevices(final OnSubnetDeviceFound listener) {
118118
this.listener.onFinished(devicesFound);
119119
}
120120

121-
private synchronized void subnetDeviceFound(SubnetInfo subnetInfo){
122-
devicesFound.add(subnetInfo);
123-
listener.onDeviceFound(subnetInfo);
121+
private synchronized void subnetDeviceFound(Device device){
122+
devicesFound.add(device);
123+
listener.onDeviceFound(device);
124124
}
125125

126126
public class SubnetDeviceFinderRunnable implements Runnable {
@@ -136,10 +136,10 @@ public void run() {
136136
InetAddress ia = InetAddress.getByName(address);
137137
PingResult pingResult = Ping.onAddress(ia).doPing();
138138
if (pingResult.isReachable) {
139-
SubnetInfo subnetInfo = new SubnetInfo(ia);
140-
subnetInfo.mac = ARPInfo.getMACFromIPAddress(ia.getHostAddress());
141-
subnetInfo.time = pingResult.timeTaken;
142-
subnetDeviceFound(subnetInfo);
139+
Device device = new Device(ia);
140+
device.mac = ARPInfo.getMACFromIPAddress(ia.getHostAddress());
141+
device.time = pingResult.timeTaken;
142+
subnetDeviceFound(device);
143143
}
144144
} catch (UnknownHostException e) {
145145
e.printStackTrace();

library/src/main/java/com/stealthcopter/networktools/subnet/SubnetInfo.java renamed to library/src/main/java/com/stealthcopter/networktools/subnet/Device.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,22 @@
22

33
import java.net.InetAddress;
44

5-
/**
6-
* Class: PortInfo
7-
* <p/>
8-
* <p/>
9-
* <p/>
10-
* Project: com.stealthcopter.portdroid portdroid
11-
* Created Date: 19/02/14 02:30
12-
*
13-
* @author <a href="mailto:[email protected]">Matthew Rollings</a>
14-
* Copyright (c) 2014 Intohand Ltd. All rights reserved.
15-
*/
16-
public class SubnetInfo {
5+
public class Device {
176
public String ip = "";
187
public String hostname = "";
198
public String mac = "";
209

2110

2211
public float time = 0;
2312

24-
public SubnetInfo(InetAddress ip) {
13+
public Device(InetAddress ip) {
2514
this.ip = ip.getHostAddress();
2615
this.hostname = ip.getCanonicalHostName();
2716
}
2817

2918
@Override
3019
public String toString() {
31-
return "SubnetInfo{" +
20+
return "Device{" +
3221
"ip='" + ip + '\'' +
3322
", hostname='" + hostname + '\'' +
3423
", mac='" + mac + '\'' +

readme.md

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ then add a library dependency. **Remember** to check for latest release [here](h
3939

4040
```groovy
4141
dependencies {
42-
compile 'com.github.stealthcopter:AndroidNetworkTools:0.2.1'
42+
compile 'com.github.stealthcopter:AndroidNetworkTools:0.3.0'
4343
}
4444
```
4545

@@ -49,6 +49,49 @@ Requires internet permission (obviously...)
4949
<uses-permission android:name="android.permission.INTERNET" />
5050
```
5151

52+
### Port Scanning
53+
54+
A simple java based TCP port scanner, fast and easy to use.
55+
56+
```java
57+
// Synchronously
58+
ArrayList<Integer> openPorts = PortScan.onAddress("192.168.0.1").setPort(21).doScan();
59+
60+
// Asynchronously
61+
PortScan.onAddress("192.168.0.1").setTimeOutMillis(1000).setPortsAll().doScan(new PortScan.PortListener() {
62+
@Override
63+
public void onResult(int portNo, boolean open) {
64+
if (open) // Stub: found open port
65+
}
66+
67+
@Override
68+
public void onFinished(ArrayList<Integer> openPorts) {
69+
// Stub: Finished scanning
70+
}
71+
});
72+
73+
```
74+
75+
### Subnet Devices
76+
77+
Finds devices that respond to ping that are on the same subnet as the current device.
78+
79+
```
80+
// Asynchronously
81+
SubnetDevices.fromLocalAddress().findDevices(new SubnetDevices.OnSubnetDeviceFound() {
82+
@Override
83+
public void onDeviceFound(Device device) {
84+
// Stub: Found subnet device
85+
}
86+
87+
@Override
88+
public void onFinished(ArrayList<Device> devicesFound) {
89+
// Stub: Finished scanning
90+
}
91+
});
92+
93+
```
94+
5295
### Ping
5396

5497
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.
@@ -68,28 +111,7 @@ Uses the native ping binary if available on the device (some devices come withou
68111

69112
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.
70113

71-
### Port Scanning
72-
73-
A simple java based TCP port scanner, fast and easy to use.
74-
75-
```java
76-
// Synchronously
77-
ArrayList<Integer> openPorts = PortScan.onAddress("192.168.0.1").setPort(21).doScan();
78-
79-
// Asynchronously
80-
PortScan.onAddress("192.168.0.1").setTimeOutMillis(1000).setPortsAll().doScan(new PortScan.PortListener() {
81-
@Override
82-
public void onResult(int portNo, boolean open) {
83-
if (open) // Stub: found open port
84-
}
85-
86-
@Override
87-
public void onFinished(ArrayList<Integer> openPorts) {
88-
// Stub: finished scanning
89-
}
90-
});
91114

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

95117
### Wake-On-Lan

0 commit comments

Comments
 (0)