Skip to content

Feature/develop #42

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

Merged
merged 7 commits into from
Jun 21, 2018
Merged
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
Binary file modified .circleci/key.p12.enc
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/captures
TODO
key.p12
/keystore
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ apply plugin: 'com.github.triplet.play'

play {
track = 'beta'
serviceAccountEmail ANDROID_NETWORK_TOOLS_SERVICE_ACCOUNT
if (project.hasProperty("ANDROID_NETWORK_TOOLS_SERVICE_ACCOUNT")) {
serviceAccountEmail ANDROID_NETWORK_TOOLS_SERVICE_ACCOUNT
}
pk12File = file('../key.p12')
}

Expand All @@ -30,8 +32,8 @@ android {
applicationId "com.stealthcotper.networktools"
minSdkVersion minSdkVer
targetSdkVersion targetSdkVer
versionCode versionName
versionName versionCode
versionName appVersionName
versionCode appVersionCode
archivesBaseName = "AndroidNetworkTools"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ subprojects {
ext.targetSdkVer = 27
ext.supportLibVer = "27.1.1"

ext.versionName = "0.4.0"
ext.versionCode = 14
ext.appVersionName = "0.4.0"
ext.appVersionCode = 14
}
15 changes: 15 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@ dependencies {
testImplementation 'org.mockito:mockito-core:2.10.0'
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

artifacts {
archives sourcesJar
archives javadocJar
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

/**
* Created by mat on 09/12/15.
* <p/>
*
* Looks at the file at /proc/net/arp to fromIPAddress ip/mac addresses from the cache
* We assume that the file has this structure:
* <p/>
*
* IP address HW type Flags HW address Mask Device
* 192.168.18.11 0x1 0x2 00:04:20:06:55:1a * eth0
* 192.168.18.36 0x1 0x2 00:22:43:ab:2a:5b * eth0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void cancel() {
* request
*
* @return - ping result
* @throws UnknownHostException - if the host cannot be resolved
*/
public PingResult doPing() throws UnknownHostException {
cancelled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public interface PortListener {
* @param address - Address to be pinged
* @return this object to allow chaining
* @throws UnknownHostException - if no IP address for the
* <code>host</code> could be found, or if a scope_id was specified
* {@code host} could be found, or if a scope_id was specified
* for a global IPv6 address.
*/
public static PortScan onAddress(String address) throws UnknownHostException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public interface OnSubnetDeviceFound {

/**
* Find devices on the subnet working from the local device ip address
*
* @return - this for chaining
*/
public static SubnetDevices fromLocalAddress() {
InetAddress ipv4 = IPTools.getLocalIPv4Address();
Expand All @@ -47,6 +49,8 @@ public static SubnetDevices fromLocalAddress() {

/**
* @param inetAddress - an ip address in the subnet
*
* @return - this for chaining
*/
public static SubnetDevices fromIPAddress(InetAddress inetAddress) {
return fromIPAddress(inetAddress.getHostAddress());
Expand All @@ -55,6 +59,8 @@ public static SubnetDevices fromIPAddress(InetAddress inetAddress) {
/**
* @param ipAddress - the ipAddress string of any device in the subnet i.e. "192.168.0.1"
* the final part will be ignored
*
* @return - this for chaining
*/
public static SubnetDevices fromIPAddress(final String ipAddress) {

Expand Down Expand Up @@ -84,6 +90,8 @@ public static SubnetDevices fromIPAddress(final String ipAddress) {

/**
* @param ipAddresses - the ipAddresses of devices to be checked
*
* @return - this for chaining
*/
public static SubnetDevices fromIPList(final List<String> ipAddresses) {

Expand All @@ -100,8 +108,10 @@ public static SubnetDevices fromIPList(final List<String> ipAddresses) {
/**
* @param noThreads set the number of threads to work with, note we default to a large number
* as these requests are network heavy not cpu heavy.
* @return self
* @throws IllegalAccessException
*
* @throws IllegalArgumentException - if invalid number of threads requested
*
* @return - this for chaining
*/
public SubnetDevices setNoThreads(int noThreads) throws IllegalArgumentException {
if (noThreads < 1) throw new IllegalArgumentException("Cannot have less than 1 thread");
Expand All @@ -112,9 +122,13 @@ public SubnetDevices setNoThreads(int noThreads) throws IllegalArgumentException
/**
* Sets the timeout for each address we try to ping
*
* @param timeOutMillis - timeout in milliseconds for each ping
*
* @return this object to allow chaining
*
* @throws IllegalArgumentException - if timeout is less than zero
*/
public SubnetDevices setTimeOutMillis(int timeOutMillis) {
public SubnetDevices setTimeOutMillis(int timeOutMillis) throws IllegalArgumentException {
if (timeOutMillis < 0) throw new IllegalArgumentException("Timeout cannot be less than 0");
this.timeOutMillis = timeOutMillis;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public void wake() throws IOException {
/**
* Asynchronous call of the wake method. This will be performed on the background thread
* and optionally fire a listener when complete, or when an error occurs
*
* @param wakeOnLanListener - listener to call on result
*/
public void wake(final WakeOnLanListener wakeOnLanListener) {

Expand All @@ -165,6 +167,9 @@ public void run() {
*
* @param ipStr - IP String to send to
* @param macStr - MAC address to wake up
*
* @throws IllegalArgumentException - invalid ip or mac
* @throws IOException - error sending packet
*/
public static void sendWakeOnLan(String ipStr, String macStr) throws IllegalArgumentException, IOException {
sendWakeOnLan(ipStr, macStr, DEFAULT_PORT, DEFAULT_TIMEOUT_MILLIS, DEFAULT_NO_PACKETS);
Expand All @@ -178,6 +183,9 @@ public static void sendWakeOnLan(String ipStr, String macStr) throws IllegalArgu
* @param port - port to send packet to
* @param timeoutMillis - timeout (millis)
* @param packets - number of packets to send
*
* @throws IllegalArgumentException - invalid ip or mac
* @throws IOException - error sending packet
*/
public static void sendWakeOnLan(final String ipStr, final String macStr, final int port, final int timeoutMillis, final int packets) throws IllegalArgumentException, IOException {
if (ipStr == null) throw new IllegalArgumentException("Address cannot be null");
Expand All @@ -193,6 +201,9 @@ public static void sendWakeOnLan(final String ipStr, final String macStr, final
* @param port - port to send packet to
* @param timeoutMillis - timeout (millis)
* @param packets - number of packets to send
*
* @throws IllegalArgumentException - invalid ip or mac
* @throws IOException - error sending packet
*/
public static void sendWakeOnLan(final InetAddress address, final String macStr, final int port, final int timeoutMillis, final int packets) throws IllegalArgumentException, IOException {
if (address == null) throw new IllegalArgumentException("Address cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ private PingNative() {

public static PingResult ping(InetAddress host, int timeOutMillis) throws IOException, InterruptedException {
PingResult pingResult = new PingResult(host);

if (host == null) {
pingResult.isReachable = false;
return pingResult;
}

StringBuilder echo = new StringBuilder();
Runtime runtime = Runtime.getRuntime();

Expand Down Expand Up @@ -86,13 +92,15 @@ public static PingResult ping(InetAddress host, int timeOutMillis) throws IOExce
* # activity_ping 321321.
* activity_ping: unknown host 321321.
*
* 1. Check if output contains 0% packet loss : Branch to success -> Get stats
* 2. Check if output contains 100% packet loss : Branch to fail -> No stats
* 3. Check if output contains 25% packet loss : Branch to partial success -> Get stats
* 1. Check if output contains 0% packet loss : Branch to success - Get stats
* 2. Check if output contains 100% packet loss : Branch to fail - No stats
* 3. Check if output contains 25% packet loss : Branch to partial success - Get stats
* 4. Check if output contains "unknown host"
*
* @param pingResult
* @param s
* @param pingResult - the current ping result
* @param s - result from ping command
*
* @return The ping result
*/
public static PingResult getPingStats(PingResult pingResult, String s) {
String pingError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static PingResult doPing(InetAddress ia, int timeOutMillis) {
* @param ia - address to ping
* @param timeOutMillis - timeout in millisecdonds
* @return - the ping results
* @throws IOException
* @throws InterruptedException
* @throws IOException - IO error running ping command
* @throws InterruptedException - thread interupt
*/
public static PingResult doNativePing(InetAddress ia, int timeOutMillis) throws IOException, InterruptedException {
return PingNative.ping(ia, timeOutMillis);
Expand All @@ -63,6 +63,12 @@ public static PingResult doNativePing(InetAddress ia, int timeOutMillis) throws
*/
public static PingResult doJavaPing(InetAddress ia, int timeOutMillis) {
PingResult pingResult = new PingResult(ia);

if (ia == null) {
pingResult.isReachable = false;
return pingResult;
}

try {
long startTime = System.nanoTime();
final boolean reached = ia.isReachable(timeOutMillis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public class PortScanTCP {
private PortScanTCP() {
}

/**
* Check if a port is open with TCP
*
* @param ia - address to scan
* @param portNo - port to scan
* @param timeoutMillis - timeout
* @return - true if port is open, false if not or unknown
*/
public static boolean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {

Socket s = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ public class PortScanUDP {
private PortScanUDP() {
}

/**
* Check if a port is open with UDP, note that this isn't reliable
* as UDP will does not send ACKs
*
* @param ia - address to scan
* @param portNo - port to scan
* @param timeoutMillis - timeout
* @return - true if port is open, false if not or unknown
*/
public static boolean scanAddress(InetAddress ia, int portNo, int timeoutMillis) {

try {
Expand Down
6 changes: 3 additions & 3 deletions scripts/github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GITHUB_UPLOAD_URL="https://uploads.github.com/repos/stealthcopter/AndroidNetwork

function create_github_release {

version=`cat $1/build.gradle | grep -m 1 versionName | cut -d'"' -f 2`
version=$2

echo "Uploading release"

Expand All @@ -33,7 +33,7 @@ function create_github_release {
echo "Found id $id"

# Upload apk file
GITHUB_RELEASE_FILE_PATH="app/build/outputs/apk/release/AndroidNetworkTools.apk"
GITHUB_RELEASE_FILE_PATH="app/build/outputs/apk/release/AndroidNetworkTools-release.apk"
GITHUB_RELASE_FILENAME="AndroidNetworkTools.apk"
curl -H "Content-Type:application/zip" -H "Authorization: token $GITHUB_RELEASE_TOKEN" --data-binary @"$GITHUB_RELEASE_FILE_PATH" $GITHUB_UPLOAD_URL$id/assets?name=$GITHUB_RELASE_FILENAME

Expand All @@ -57,7 +57,7 @@ function create_github_release {

if [[ $GIT_TAG != *"undefined"* ]]; then
echo "Creating github release for tag $GIT_TAG"
if create_github_release $GITHUB_RELEASE_MODULE; then
if create_github_release $GITHUB_RELEASE_MODULE $GIT_TAG; then
webhook $GITHUB_RELEASE_MODULE "$GITHUB_RELEASE_NAME" "Created github release for tag $TAG"
else
webhook $GITHUB_RELEASE_MODULE "$GITHUB_RELEASE_NAME" "Failed to create github release for tag $TAG :("
Expand Down
4 changes: 2 additions & 2 deletions scripts/upload-apks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function upload_to_beta {
function upload_to_google_play {
echo "Uploading $1 to Google Play"

if ./gradlew :$1:publishApkRegularRelease ; then
if ./gradlew :$1:publishApkRelease ; then
webhook $1 "$APP_RELEASE_NAME" "Uploading to Google Play Succeeded"
else
webhook $1 "$APP_RELEASE_NAME" "Uploading to Google Play FAILED :("
Expand All @@ -39,7 +39,7 @@ function upload_to_google_play {
# Print the git commit message
echo "Git commit message: ${GIT_COMMIT_DESC}"

if [[ $GIT_COMMIT_DESC == *"#DEPLOY"* ]]; then
if [[ $GIT_COMMIT_DESC == *"#PLAY_BETA"* ]]; then
upload_to_google_play "app"
else
echo "Not publishing to Google Play as deploy not found in commit message"
Expand Down