Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ci intergration #111

Open
wants to merge 18 commits into
base: feature/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/android:api-25-alpha
- image: circleci/android:api-29
environment:
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
steps:
Expand All @@ -15,7 +15,7 @@ jobs:
name: Copy Environment Vars
command: scripts/cp-env-to-properties.sh

# Decrypt any secret files / keys
# Decrypt any secret files / keys
- run:
name: Decrypt secret files
command: scripts/decrypt-secrets.sh
Expand Down
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ android {
applicationId "com.stealthcotper.networktools"
minSdkVersion minSdkVer
targetSdkVersion targetSdkVer
versionName appVersionName
versionCode appVersionCode

// When updating these, remember to update the vars in the root build.gradle
versionName "0.4.5"
versionCode 19

archivesBaseName = "AndroidNetworkTools"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".ANTApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.stealthcotper.networktools;

import android.app.Application;

public class ANTApplication extends Application {

@Override
public void onCreate() {
initStrictMode();
super.onCreate();
}

private void initStrictMode() {
if (BuildConfig.DEBUG) {

// Let's be super strict so that we can discover bugs during testing

// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
// .detectAll()
// .penaltyLog()
//// .penaltyDeath()
// .build());
//
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
// .detectAll()
// .penaltyLog()
//// .penaltyDeath()
// .build());
}
}


}
74 changes: 70 additions & 4 deletions app/src/main/java/com/stealthcotper/networktools/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;

import com.stealthcopter.networktools.ARPInfo;
Expand All @@ -25,12 +27,18 @@

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

private TextView resultText;
private EditText editIpAddress;
private ScrollView scrollView;
private Button pingButton;
private Button wolButton;
private Button portScanButton;
private Button subnetDevicesButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -41,6 +49,11 @@ protected void onCreate(Bundle savedInstanceState) {

resultText = findViewById(R.id.resultText);
editIpAddress = findViewById(R.id.editIpAddress);
scrollView = findViewById(R.id.scrollView1);
pingButton = findViewById(R.id.pingButton);
wolButton = findViewById(R.id.wolButton);
portScanButton = findViewById(R.id.portScanButton);
subnetDevicesButton = findViewById(R.id.subnetDevicesButton);

InetAddress ipAddress = IPTools.getLocalIPv4Address();
if (ipAddress != null){
Expand Down Expand Up @@ -118,6 +131,23 @@ private void appendResultsText(final String text) {
@Override
public void run() {
resultText.append(text + "\n");
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
}
});
}

private void setEnabled(final View view, final boolean enabled) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (view != null) {
view.setEnabled(enabled);
}
}
});
}
Expand All @@ -130,8 +160,19 @@ private void doPing() throws Exception {
return;
}

setEnabled(pingButton, false);

// Perform a single synchronous ping
PingResult pingResult = Ping.onAddress(ipAddress).setTimeOutMillis(1000).doPing();
PingResult pingResult = null;
try {
pingResult = Ping.onAddress(ipAddress).setTimeOutMillis(1000).doPing();
} catch (UnknownHostException e) {
e.printStackTrace();
appendResultsText(e.getMessage());
setEnabled(pingButton, true);
return;
}


appendResultsText("Pinging Address: " + pingResult.getAddress().getHostAddress());
appendResultsText("HostName: " + pingResult.getAddress().getHostName());
Expand All @@ -142,7 +183,11 @@ private void doPing() throws Exception {
Ping.onAddress(ipAddress).setTimeOutMillis(1000).setTimes(5).doPing(new Ping.PingListener() {
@Override
public void onResult(PingResult pingResult) {
appendResultsText(String.format("%.2f ms", pingResult.getTimeTaken()));
if (pingResult.isReachable) {
appendResultsText(String.format("%.2f ms", pingResult.getTimeTaken()));
} else {
appendResultsText(getString(R.string.timeout));
}
}

@Override
Expand All @@ -151,11 +196,13 @@ public void onFinished(PingStats pingStats) {
pingStats.getNoPings(), pingStats.getPacketsLost()));
appendResultsText(String.format("Min/Avg/Max Time: %.2f/%.2f/%.2f ms",
pingStats.getMinTimeTaken(), pingStats.getAverageTimeTaken(), pingStats.getMaxTimeTaken()));
setEnabled(pingButton, true);
}

@Override
public void onError(Exception e) {
// TODO: STUB METHOD
setEnabled(pingButton, true);
}
});

Expand All @@ -169,13 +216,16 @@ private void doWakeOnLan() throws IllegalArgumentException {
return;
}

setEnabled(wolButton, false);

appendResultsText("IP address: " + ipAddress);

// Get mac address from IP (using arp cache)
String macAddress = ARPInfo.getMACFromIPAddress(ipAddress);

if (macAddress == null) {
appendResultsText("Could not fromIPAddress MAC address, cannot send WOL packet without it.");
setEnabled(wolButton, true);
return;
}

Expand All @@ -187,7 +237,10 @@ private void doWakeOnLan() throws IllegalArgumentException {
WakeOnLan.sendWakeOnLan(ipAddress, macAddress);
appendResultsText("WOL Packet sent");
} catch (IOException e) {
appendResultsText(e.getMessage());
e.printStackTrace();
} finally {
setEnabled(wolButton, true);
}
}

Expand All @@ -196,17 +249,20 @@ private void doPortScan() throws Exception {

if (TextUtils.isEmpty(ipAddress)) {
appendResultsText("Invalid Ip Address");
setEnabled(portScanButton, true);
return;
}

setEnabled(portScanButton, false);

// Perform synchronous port scan
appendResultsText("PortScanning IP: " + ipAddress);
ArrayList<Integer> openPorts = PortScan.onAddress(ipAddress).setPort(21).setMethodTCP().doScan();

final long startTimeMillis = System.currentTimeMillis();

// Perform an asynchronous port scan
PortScan.onAddress(ipAddress).setPortsAll().setMethodTCP().doScan(new PortScan.PortListener() {
PortScan portScan = PortScan.onAddress(ipAddress).setPortsAll().setMethodTCP().doScan(new PortScan.PortListener() {
@Override
public void onResult(int portNo, boolean open) {
if (open) appendResultsText("Open: " + portNo);
Expand All @@ -216,17 +272,22 @@ public void onResult(int portNo, boolean open) {
public void onFinished(ArrayList<Integer> openPorts) {
appendResultsText("Open Ports: " + openPorts.size());
appendResultsText("Time Taken: " + ((System.currentTimeMillis() - startTimeMillis)/1000.0f));
setEnabled(portScanButton, true);
}
});

// Below is example of how to cancel a running scan
// portScan.cancel();
}


private void findSubnetDevices() {

setEnabled(subnetDevicesButton, false);

final long startTimeMillis = System.currentTimeMillis();

SubnetDevices.fromLocalAddress().findDevices(new SubnetDevices.OnSubnetDeviceFound() {
SubnetDevices subnetDevices = SubnetDevices.fromLocalAddress().findDevices(new SubnetDevices.OnSubnetDeviceFound() {
@Override
public void onDeviceFound(Device device) {
appendResultsText("Device: " + device.ip+" "+ device.hostname);
Expand All @@ -237,8 +298,13 @@ public void onFinished(ArrayList<Device> devicesFound) {
float timeTaken = (System.currentTimeMillis() - startTimeMillis)/1000.0f;
appendResultsText("Devices Found: " + devicesFound.size());
appendResultsText("Finished "+timeTaken+" s");
setEnabled(subnetDevicesButton, true);
}
});

// Below is example of how to cancel a running scan
// subnetDevices.cancel();

}

@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
</LinearLayout>

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_horizontal_margin"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<string name="port_scan">Port Scan</string>
<string name="github_page">Github</string>
<string name="github_url">https://github.com/stealthcopter/AndroidNetworkTools</string>
<string name="subnet">Subnet Devices</string>
<string name="subnet">Subnet Devices</string>
<string name="timeout">** Timeout **</string>
</resources>
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -24,12 +24,13 @@ task clean(type: Delete) {
}

subprojects {
ext.compileSdkVer = 27
ext.buildToolsVer = "27.0.3"
ext.compileSdkVer = 29
ext.buildToolsVer = "29.0.1"
ext.minSdkVer = 14
ext.targetSdkVer = 27
ext.targetSdkVer = 29
ext.supportLibVer = "27.1.1"

ext.appVersionName = "0.4.0"
ext.appVersionCode = 14
// When updating these, remember to update the vars in app/build.gradle (for FDroid comptability)
ext.appVersionName = "0.4.5"
ext.appVersionCode = 19
}
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-GB/changelogs/19.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Added fastlane structure for F-Droid inclusion
11 changes: 11 additions & 0 deletions fastlane/metadata/android/en-GB/full_description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This is a sample application from the open source project Android Network Tools. If you are looking for a more complete network scanning tool, please see my other app Portdroid.

It demonstrates the following features of the library:

• Pinging
• Port Scanning
• Finding devices on your network
• Wake-on-lan

The project is hosted on github. Bug reports, feature requests and contributions are all welcome:
https://github.com/stealthcopter/AndroidNetworkTools
Binary file added fastlane/metadata/android/en-GB/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-GB/short_description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the sample application from Android Network Tools open source library
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-GB/title.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Network Tools Library
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue May 01 19:31:51 BST 2018
#Sun Nov 03 10:39:47 GMT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
5 changes: 0 additions & 5 deletions library/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private MACTools() {
* Validates a provided MAC address
*
* @param macAddress - the MAC address to check
* @return - true if it is valid MAC address in IEEE802 format (either hyphen or colon seperated)
* @return - true if it is valid MAC address in IEEE802 format (either hyphen or colon separated)
* eg: "01:23:45:67:89:AB" or "01-23-45-67-89-AB"
*/
public static boolean isValidMACAddress(final String macAddress) {
Expand All @@ -28,7 +28,7 @@ public static boolean isValidMACAddress(final String macAddress) {
/**
* Convert a MAC string to bytes
*
* @param macStr - MAC string in IEEE802 format (either hyphen or colon seperated)
* @param macStr - MAC string in IEEE802 format (either hyphen or colon separated)
* eg: "01:23:45:67:89:AB" or "01-23-45-67-89-AB"
* @return - MAC formatted in bytes
* @throws IllegalArgumentException - if mac address is invalid
Expand Down
Loading