Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michalis Mavris authored and Michalis Mavris committed Jul 8, 2017
2 parents c85b195 + dfda989 commit 33bd7ea
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 122 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3
6 changes: 3 additions & 3 deletions MMLanScan.podspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Pod::Spec.new do |s|
s.name = 'MMLanScan'
s.version = '2.1.2'
s.summary = 'MMLanScan is an open source project for iOS that helps you scan your network and shows the available devices'
s.version = '2.2.0'
s.summary = 'MMLanScan is an open source project for iOS that helps you scan your network and shows the available devices.'

s.description = <<-DESC
MMLanScan is an open source project for iOS that helps you scan your network and shows the available devices and their MAC Address, hostname and Brand name.
MMLanScan is an open source project for iOS that helps you scan your network and shows the available devices and their MAC Address, hostname and Brand name. For those updating from 2.1.2 please note that "Device" class has been renamed to "MMDevice".
Features
+ Scans and finds available hosts in your network
Expand Down
4 changes: 2 additions & 2 deletions MMLanScan/Misc/LANProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import <Foundation/Foundation.h>

@class Device;
@class MMDevice;

@interface LANProperties : NSObject

Expand All @@ -18,7 +18,7 @@
Device *newDevice = [LANProperties localIPAddress];
@endcode
*/
+(Device*)localIPAddress;
+(MMDevice*)localIPAddress;

/*!
@brief This method returns the hostname of a specific IP Address
Expand Down
10 changes: 6 additions & 4 deletions MMLanScan/Misc/LANProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#import <SystemConfiguration/CaptiveNetwork.h>
#import "NetworkCalculator.h"
#import "LANProperties.h"
#import "Device.h"
#import "MMDevice.h"
#import <ifaddrs.h>
#import <arpa/inet.h>
#include <netdb.h>

@implementation LANProperties

#pragma mark - Public methods
+(Device*)localIPAddress {
+(MMDevice*)localIPAddress {

Device *localDevice = [[Device alloc]init];
MMDevice *localDevice = [[MMDevice alloc]init];

localDevice.ipAddress = @"error";

Expand Down Expand Up @@ -54,10 +54,12 @@ +(Device*)localIPAddress {

//In case we failed to fetch IP address
if ([localDevice.ipAddress isEqualToString:@"error"]) {

return nil;
}

//Mark the device as the local IP
localDevice.isLocalDevice = YES;

return localDevice;
}

Expand Down
5 changes: 2 additions & 3 deletions MMLanScan/Misc/MACOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

#import "SimplePing.h"

@class Device;
@class MMDevice;

@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;
-(nullable instancetype)initWithIPToRetrieveMAC:(nonnull NSString*)ip andBrandDictionary:(nullable NSDictionary*)brandDictionary andCompletionHandler:(nullable void (^)(NSError * _Nullable error, NSString * _Nonnull ip,MMDevice * _Nonnull device))result;
@end
21 changes: 9 additions & 12 deletions MMLanScan/Misc/MACOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#import "MACOperation.h"
#import "LANProperties.h"
#import "MacFinder.h"
#import "Device.h"
#import "MMDevice.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, copy) void (^result)(NSError * _Nullable error, NSString * _Nonnull ip,MMDevice * _Nonnull device);
@property(nonatomic,strong)MMDevice *device;
@property(nonatomic,weak)NSDictionary *brandDictionary;
@end

Expand All @@ -26,20 +26,18 @@ @implementation MACOperation {
NSError *errorMessage;
}

-(instancetype)initWithIPToRetrieveMAC:(NSString*)ip andBrandDictionary:(NSDictionary*)brandDictionary andCompletionHandler:(nullable void (^)(NSError * _Nullable error, NSString * _Nonnull ip,Device * _Nonnull device))result;{
-(instancetype)initWithIPToRetrieveMAC:(NSString*)ip andBrandDictionary:(NSDictionary*)brandDictionary andCompletionHandler:(nullable void (^)(NSError * _Nullable error, NSString * _Nonnull ip,MMDevice * _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;
_device = [[MMDevice alloc]init];
self.name = ip;
_ipStr= ip;
_result = result;
_brandDictionary=brandDictionary;
_isExecuting = NO;
_isFinished = NO;

}

return self;
Expand All @@ -54,7 +52,6 @@ -(void)start {
return;
}


[self willChangeValueForKey:@"isExecuting"];
_isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
Expand Down
4 changes: 2 additions & 2 deletions MMLanScan/Misc/MMLANScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MMLanScannerStatus;

#import <Foundation/Foundation.h>

@class Device;
@class MMDevice;
@protocol MMLANScannerDelegate;
#pragma mark - MMLANScanner Protocol
//The delegate protocol for MMLanScanner
Expand All @@ -33,7 +33,7 @@ MMLanScannerStatus;
}
@endcode
*/
- (void)lanScanDidFindNewDevice:(Device*)device;
- (void)lanScanDidFindNewDevice:(MMDevice*)device;

/*!
@brief This delegate is called when the scan has finished
Expand Down
24 changes: 13 additions & 11 deletions MMLanScan/Misc/MMLANScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#import "MMLANScanner.h"
#import "MACOperation.h"
#import "MacFinder.h"
#import "Device.h"
#import "MMDevice.h"

@interface MMLANScanner ()
@property (nonatomic,strong) Device *device;
@property (nonatomic,strong) MMDevice *device;
@property (nonatomic,strong) NSArray *ipsToPing;
@property (nonatomic,assign) float currentHost;
@property (nonatomic,strong) NSDictionary *brandDictionary;
Expand All @@ -33,22 +33,22 @@ -(instancetype)initWithDelegate:(id<MMLANScannerDelegate>)delegate {

if (self) {
//Setting the delegate
self.delegate=delegate;
_delegate=delegate;

//Initializing the dictionary that holds the Brands name for each MAC Address
self.brandDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]];
_brandDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]];

//Initializing the NSOperationQueue
self.queue = [[NSOperationQueue alloc] init];
_queue = [[NSOperationQueue alloc] init];
//Setting the concurrent operations to 50
[self.queue setMaxConcurrentOperationCount:50];
[_queue setMaxConcurrentOperationCount:50];

//Add observer to notify the delegate when queue is empty.
[self.queue addObserver:self forKeyPath:@"operations" options:0 context:nil];
[_queue addObserver:self forKeyPath:@"operations" options:0 context:nil];

isFinished = NO;
isCancelled = NO;
self.isScanning = NO;
_isScanning = NO;
}

return self;
Expand All @@ -75,6 +75,10 @@ -(void)start {
return;
}

if ([self.delegate respondsToSelector:@selector(lanScanDidFindNewDevice:)]) {
[self.delegate lanScanDidFindNewDevice:self.device];
}

//Getting the available IPs to ping based on our network subnet.
self.ipsToPing = [LANProperties getAllHostsForIP:self.device.ipAddress andSubnet:self.device.subnetMask];

Expand All @@ -98,7 +102,7 @@ -(void)start {
}];

//The Find MAC Address for each operation
MACOperation *macOperation = [[MACOperation alloc] initWithIPToRetrieveMAC:ipStr andBrandDictionary:self.brandDictionary andCompletionHandler:^(NSError * _Nullable error, NSString * _Nonnull ip, Device * _Nonnull device) {
MACOperation *macOperation = [[MACOperation alloc] initWithIPToRetrieveMAC:ipStr andBrandDictionary:self.brandDictionary andCompletionHandler:^(NSError * _Nullable error, NSString * _Nonnull ip, MMDevice * _Nonnull device) {

if (!weakSelf) {
return;
Expand All @@ -108,7 +112,6 @@ -(void)start {
weakSelf.currentHost = weakSelf.currentHost + 0.5;

if (!error) {

//Letting know the delegate that found a new device (on Main Thread)
dispatch_async (dispatch_get_main_queue(), ^{
if ([weakSelf.delegate respondsToSelector:@selector(lanScanDidFindNewDevice:)]) {
Expand Down Expand Up @@ -136,7 +139,6 @@ -(void)start {
}

-(void)stop {

isCancelled = YES;
[self.queue cancelAllOperations];
[self.queue waitUntilAllOperationsAreFinished];
Expand Down
1 change: 0 additions & 1 deletion MMLanScan/Misc/NetworkCalculator.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ +(NSArray*)getAllHostsForIP:(NSString*)ipAddress andSubnet:(NSString*)subnetMask

//Check if valid IP
if (![self isValidIPAddress:ipAddress] || ![self isValidIPAddress:subnetMask]) {

return nil;
}

Expand Down
1 change: 0 additions & 1 deletion MMLanScan/Misc/PingOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#import "SimplePing.h"

@interface PingOperation : NSOperation <SimplePingDelegate> {

BOOL _isFinished;
BOOL _isExecuting;
}
Expand Down
19 changes: 5 additions & 14 deletions MMLanScan/Misc/PingOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "PingOperation.h"
#import "Device.h"
#import "MMDevice.h"
#import "LANProperties.h"
#import "MacFinder.h"

Expand Down Expand Up @@ -37,29 +37,26 @@ -(instancetype)initWithIPToPing:(NSString*)ip andCompletionHandler:(nullable voi

if (self) {
self.name = ip;
self.ipStr= ip;
self.simplePing = [SimplePing simplePingWithHostName:ip];
self.simplePing.delegate = self;
self.result = result;
_ipStr= ip;
_simplePing = [SimplePing simplePingWithHostName:ip];
_simplePing.delegate = self;
_result = result;
_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"];
Expand All @@ -83,7 +80,6 @@ -(void)start {

}
-(void)ping {

[self.simplePing start];
}
- (void)finishedPing {
Expand Down Expand Up @@ -141,28 +137,24 @@ - (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address {
}

[pinger sendPingWithData:nil];
//NSLog(@"start");
}

- (void)simplePing:(SimplePing *)pinger didFailWithError:(NSError *)error {

// NSLog(@"failed");
[pingTimer invalidate];
errorMessage = error;
[self finishedPing];
}

- (void)simplePing:(SimplePing *)pinger didFailToSendPacket:(NSData *)packet error:(NSError *)error {

//NSLog(@"failed");
[pingTimer invalidate];
errorMessage = error;
[self finishedPing];
}

- (void)simplePing:(SimplePing *)pinger didReceivePingResponsePacket:(NSData *)packet {

//NSLog(@"success");
[pingTimer invalidate];
[self finishedPing];
}
Expand All @@ -173,7 +165,6 @@ - (void)simplePing:(SimplePing *)pinger didSendPacket:(NSData *)packet {
}

- (void)pingTimeOut:(NSTimer *)timer {
//NSLog(@"Ping timeout occurred, host not reachable");
// Move to next host
errorMessage = [NSError errorWithDomain:@"Ping timeout" code:11 userInfo:nil];
[self finishedPing];
Expand Down
11 changes: 6 additions & 5 deletions MMLanScan/Objects/Device.h → MMLanScan/Objects/MMDevice.h
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
//
// Device.h
// MMDevice.h
// MMLanScanDemo
//
// Created by Michalis Mavris on 06/08/16.
// Copyright © 2016 Miksoft. All rights reserved.
// Created by Michalis Mavris on 08/07/2017.
// Copyright © 2017 Miksoft. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Device : NSObject
@interface MMDevice : NSObject

@property (nonatomic,strong) NSString *hostname;
@property (nonatomic,strong) NSString *ipAddress;
@property (nonatomic,strong) NSString *macAddress;
@property (nonatomic,strong) NSString *subnetMask;
@property (nonatomic,strong) NSString *brand;

@property (nonatomic,assign) BOOL isLocalDevice;
-(NSString*)macAddressLabel;
@end
Loading

0 comments on commit 33bd7ea

Please sign in to comment.