Skip to content

Commit 8600a55

Browse files
committed
Added start of traceroute
2 parents 702090d + cf6420a commit 8600a55

File tree

16 files changed

+473
-101
lines changed

16 files changed

+473
-101
lines changed

.circleci/config.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ jobs:
3131
name: Run Tests
3232
command: ./gradlew test
3333

34-
- store_test_results:
35-
path: app/build/reports
36-
destination: reports
34+
#- store_test_results:
35+
#path: app/build/reports
36+
#destination: reports
3737

3838
- store_test_results:
39+
name: Save Libary Unit Tests
3940
path: library/build/reports
4041
destination: reports
4142

.circleci/keystore.enc

-3.31 KB
Binary file not shown.

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 versionCode
34+
versionName versionName
3535
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3636
}
3737

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

Lines changed: 10 additions & 8 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.SubnetDevice;
24+
import com.stealthcopter.networktools.subnet.Device;
2525

2626
import java.io.IOException;
2727
import java.net.InetAddress;
@@ -44,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
4444

4545
InetAddress ipAddress = IPTools.getLocalIPv4Address();
4646
if (ipAddress != null){
47-
editIpAddress.setText(ipAddress.toString());
47+
editIpAddress.setText(ipAddress.getHostAddress());
4848
}
4949

5050
findViewById(R.id.pingButton).setOnClickListener(new View.OnClickListener() {
@@ -198,8 +198,10 @@ private void doPortScan() throws Exception {
198198
appendResultsText("PortScanning IP: " + ipAddress);
199199
ArrayList<Integer> openPorts = PortScan.onAddress(ipAddress).setPort(21).doScan();
200200

201+
final long startTimeMillis = System.currentTimeMillis();
202+
201203
// Perform an asynchronous port scan
202-
PortScan.onAddress(ipAddress).setTimeOutMillis(1000).setPortsAll().doScan(new PortScan.PortListener() {
204+
PortScan.onAddress(ipAddress).setPortsAll().doScan(new PortScan.PortListener() {
203205
@Override
204206
public void onResult(int portNo, boolean open) {
205207
if (open) appendResultsText("Open: " + portNo);
@@ -208,6 +210,7 @@ public void onResult(int portNo, boolean open) {
208210
@Override
209211
public void onFinished(ArrayList<Integer> openPorts) {
210212
appendResultsText("Open Ports: " + openPorts.size());
213+
appendResultsText("Time Taken: " + ((System.currentTimeMillis() - startTimeMillis)/1000.0f));
211214
}
212215
});
213216

@@ -218,17 +221,16 @@ private void findSubnetDevices() {
218221

219222
final long startTimeMillis = System.currentTimeMillis();
220223

221-
String partialIpAddress = editIpAddress.getText().toString();
222-
223224
SubnetDevices.fromLocalAddress().findDevices(new SubnetDevices.OnSubnetDeviceFound() {
224225
@Override
225-
public void onDeviceFound(SubnetDevice subnetDevice) {
226-
appendResultsText("Device: " + subnetDevice.ip+" "+ subnetDevice.hostname);
226+
public void onDeviceFound(Device device) {
227+
appendResultsText("Device: " + device.ip+" "+ device.hostname);
227228
}
228229

229230
@Override
230-
public void onFinished(ArrayList<SubnetDevice> devicesFound) {
231+
public void onFinished(ArrayList<Device> devicesFound) {
231232
float timeTaken = (System.currentTimeMillis() - startTimeMillis)/1000.0f;
233+
appendResultsText("Devices Found: " + devicesFound.size());
232234
appendResultsText("Finished "+timeTaken+" s");
233235
}
234236
});

app/src/main/res/layout/content_main.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@
5454

5555
<Button
5656
android:id="@+id/wolButton"
57-
android:layout_width="0dp"
57+
android:layout_width="wrap_content"
5858
android:layout_height="wrap_content"
59-
android:layout_weight="1"
6059
android:text="@string/wol"
6160
/>
6261
<Button

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 versionCode
11+
versionName versionName
1212
}
1313
buildTypes {
1414
release {

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,38 @@ public static ArrayList<InetAddress> getLocalIPv4Addresses() {
9292
}
9393

9494

95+
/**
96+
* Check if the provided ip address refers to the localhost
97+
*
98+
* https://stackoverflow.com/a/2406819/315998
99+
*
100+
* @param addr - address to check
101+
* @return - true if ip address is self
102+
*/
103+
public static boolean isIpAddressLocalhost(InetAddress addr) {
104+
// Check if the address is a valid special local or loop back
105+
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
106+
return true;
107+
108+
// Check if the address is defined on any interface
109+
try {
110+
return NetworkInterface.getByInetAddress(addr) != null;
111+
} catch (SocketException e) {
112+
return false;
113+
}
114+
}
115+
116+
/**
117+
* Check if the provided ip address refers to the localhost
118+
*
119+
* https://stackoverflow.com/a/2406819/315998
120+
*
121+
* @param addr - address to check
122+
* @return - true if ip address is self
123+
*/
124+
public static boolean isIpAddressLocalNetwork(InetAddress addr) {
125+
return addr.isSiteLocalAddress();
126+
}
127+
128+
95129
}

0 commit comments

Comments
 (0)