Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
mavris committed Nov 7, 2016
2 parents 1c08120 + ec2eb61 commit e4ac746
Show file tree
Hide file tree
Showing 50 changed files with 2,327 additions and 396 deletions.
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

##MacOSX Generated
**/.DS_Store
.DS_Store

## Various settings
*.pbxuser
!default.pbxuser
Expand Down Expand Up @@ -49,4 +52,11 @@ Carthage/Build
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md

fastlane/report.xml
fastlane/screenshots
fastlane/screenshots
.DS_Store

MMLanScanDemo/.DS_Store

MMLanScanDemo/.DS_Store

.DS_Store
Binary file modified LanScan.gif
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 MMLanScan/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>

@interface Device : NSObject

@property (nonatomic,strong) NSString *hostname;
@property (nonatomic,strong) NSString *ipAddress;
@property (nonatomic,strong) NSString *macAddress;
Expand Down
2 changes: 1 addition & 1 deletion MMLanScan/Device.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ -(NSString*)macAddressLabel {

-(NSString*)brand {

if(_brand==nil|| _brand == NULL || _brand==(id)[NSNull null]){
if(_brand==nil || _brand == NULL || _brand==(id)[NSNull null]){

return @"";
}
Expand Down
4 changes: 2 additions & 2 deletions MMLanScan/LANProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// Copyright © 2016 Miksoft. All rights reserved.
//

#import <SystemConfiguration/CaptiveNetwork.h>
#import "NetworkCalculator.h"
#import "LANProperties.h"
#import "Device.h"
#import <ifaddrs.h>
#import <arpa/inet.h>
#include <netdb.h>
#import <SystemConfiguration/CaptiveNetwork.h>
#import "NetworkCalculator.h"

@implementation LANProperties

Expand Down
19 changes: 19 additions & 0 deletions MMLanScan/MACOperation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// PingOperation.h
//
// Created by Michael Mavris on 03/11/2016.
// Copyright © 2016 Miksoft. All rights reserved.
//

#import "SimplePing.h"

@class Device;

@interface MACOperation: NSOperation {

BOOL _isFinished;
BOOL _isExecuting;
}

-(nullable instancetype)initWithIPToRetrieveMAC:(nonnull NSString*)ip andBrandDictionary:(nullable NSDictionary*)brandDictionary andCompletionHandler:(nullable void (^)(NSError * _Nullable error, NSString * _Nonnull ip,Device * _Nonnull device))result;
@end
118 changes: 118 additions & 0 deletions MMLanScan/MACOperation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// PingOperation.m
//
// Created by Michael Mavris on 03/11/2016.
// Copyright © 2016 Miksoft. All rights reserved.
//

#import "MACOperation.h"
#import "LANProperties.h"
#import "MacFinder.h"
#import "Device.h"

@interface MACOperation ()
@property (nonatomic,strong) NSString *ipStr;
@property (nonatomic, copy) void (^result)(NSError * _Nullable error, NSString * _Nonnull ip,Device * _Nonnull device);
@property(nonatomic,strong)Device *device;
@property(nonatomic,weak)NSDictionary *brandDictionary;
@end

@interface MACOperation()
- (void)finish;
@end

@implementation MACOperation {

NSError *errorMessage;
}

-(instancetype)initWithIPToRetrieveMAC:(NSString*)ip andBrandDictionary:(NSDictionary*)brandDictionary andCompletionHandler:(nullable void (^)(NSError * _Nullable error, NSString * _Nonnull ip,Device * _Nonnull device))result;{

self = [super init];

if (self) {

self.device = [[Device alloc]init];
self.name = ip;
self.ipStr= ip;
self.result = result;
self.brandDictionary=brandDictionary;
_isExecuting = NO;
_isFinished = NO;

}

return self;
};

-(void)start {

if ([self isCancelled]) {
[self willChangeValueForKey:@"isFinished"];
_isFinished = YES;
[self didChangeValueForKey:@"isFinished"];
return;
}


[self willChangeValueForKey:@"isExecuting"];
_isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];

[self getMACDetails];
}
-(void)finishMAC {

if (self.isCancelled) {
[self finish];
return;
}

if (self.result) {
self.result(errorMessage,self.name,self.device);
}

[self finish];
}

-(void)finish {

[self willChangeValueForKey:@"isExecuting"];
[self willChangeValueForKey:@"isFinished"];

_isExecuting = NO;
_isFinished = YES;

[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];

}

- (BOOL)isExecuting {
return _isExecuting;
}

- (BOOL)isFinished {
return _isFinished;
}

#pragma mark - Ping Result callback
-(void)getMACDetails{

self.device.ipAddress=self.ipStr;
self.device.macAddress =[[MacFinder ip2mac:self.device.ipAddress] uppercaseString];
self.device.hostname = [LANProperties getHostFromIPAddress:self.ipStr];

if (!self.device.macAddress) {

errorMessage = [NSError errorWithDomain:@"MAC Address Not Exist" code:10 userInfo:nil];
}
else {
//Retrieving brand for the specific MAC Address
self.device.brand = [self.brandDictionary objectForKey:[[self.device.macAddress substringWithRange:NSMakeRange(0, 8)] stringByReplacingOccurrencesOfString:@":" withString:@"-"]];
}

[self finishMAC];
}

@end
61 changes: 43 additions & 18 deletions MMLanScan/MMLANScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
// Copyright © 2016 Miksoft. All rights reserved.
//

typedef enum {
MMLanScannerStatusFinished,
MMLanScannerStatusCancelled
}
MMLanScannerStatus;

#import <Foundation/Foundation.h>

@class Device;
#pragma mark - Delegates
@protocol MMLANScannerDelegate;
#pragma mark - MMLANScanner Protocol
//The delegate protocol for MMLanScanner
@protocol MMLANScannerDelegate <NSObject>

@optional

@required
/*!
@brief This delegate is called each time that MMLANSCanner discovers a new IP
@param device The device object that contains the IP Address, MAC Address and hostname
Expand All @@ -24,49 +30,68 @@
[self.connectedDevices addObject:device];
}
}
}
@endcode
*/
- (void)lanScanDidFindNewDevice:(Device*)device;

/*!
@brief This delegate is called when the scan has finished
@code
-(void)lanScanDidFinishScanning{
[[[UIAlertView alloc] initWithTitle:@"Scan Finished" message:[NSString stringWithFormat:@"Number of devices connected to the Local Area Network : %lu", (unsigned long)self.connectedDevices.count] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
}
@endcode
*/
- (void)lanScanDidFinishScanning;
- (void)lanScanDidFinishScanningWithStatus:(MMLanScannerStatus)status;

/*!
@brief This delegate is called in case the LAN scan has failed
*/
- (void)lanScanDidFailedToScan;

@optional
/*!
@brief This delegate is called each time a new host is pinged
@param pingedHost The number of hosts pinged so far
@param overalHosts The number of all available hosts to ping
@param pingedHosts The number of hosts pinged so far
@param overallHosts The number of all available hosts to ping
@code
- (void)lanScanProgressPinged:(NSInteger)pingedHosts from:(NSInteger)overallHosts {
[self.progressView setProgress:(float)pingedHosts/overallHosts];
}
@endcode
*/
- (void)lanScanProgressPinged:(NSInteger)pingedHosts from:(NSInteger)overallHosts;

/*!
@brief This delegate is called in case the LAN scan has failed
*/
- (void)lanScanDidFailedToScan;
- (void)lanScanProgressPinged:(float)pingedHosts from:(NSInteger)overallHosts;

@end

#pragma mark - Public methods
@interface MMLANScanner : NSObject <MMLANScannerDelegate>
@property(nonatomic,weak) id<MMLANScannerDelegate> delegate;
@interface MMLANScanner : NSObject

@property(nonatomic,weak) id<MMLANScannerDelegate> delegate;
/*!
@brief Custom init method. Always use this method to initialize MMLANScanner
@param delegate The object that will receive the messages from MMLANScanner
@code
self.lanScanner = [[MMLANScanner alloc] initWithDelegate:self];
@endcode
*/
-(instancetype)initWithDelegate:(id <MMLANScannerDelegate>)delegate;
/*!
@brief A bool property that lets you know when the MMLANScanner is scanning. KVO compliant
*/
@property(nonatomic,assign,readonly)BOOL isScanning;

/*!
@brief Starts the scanning
*/
- (void)start;
/*!
@brief Stops the scanning
*/
- (void)stop;
@end
Loading

0 comments on commit e4ac746

Please sign in to comment.