forked from illuminati1911/LANScan-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ville Välimaa
committed
Mar 6, 2017
1 parent
5ee94e6
commit 40d1100
Showing
30 changed files
with
2,731 additions
and
1,497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// PortScanner.swift | ||
// LANScan | ||
// | ||
// Created by Ville Välimaa on 04/03/2017. | ||
// Copyright © 2017 Ville Välimaa. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftSocket | ||
import ReactiveCocoa | ||
|
||
class PortScanner { | ||
|
||
static func scanPortsOn(host:Host) -> RACSignal { | ||
guard let ip = host.ipAddress else { return RACSignal() } | ||
return RACSignal.createSignal({ (subscriber: RACSubscriber?) -> RACDisposable? in | ||
DispatchQueue.global(qos: .background).async { | ||
(Array(1...100) | ||
.map { signalForPort(port: $0, ipAddress: ip) } as NSArray | ||
|> RACSignal.combineLatest) | ||
.deliverOnMainThread() | ||
.subscribeNext({ (services:Any?) in | ||
let finalServices = ((services as! RACTuple).allObjects() as! Array<String>) | ||
.filter { $0 != Constants.NO_SERVICE } | ||
subscriber!.sendNext(finalServices) | ||
subscriber?.sendCompleted() | ||
}) | ||
} | ||
return RACDisposable(block: { | ||
}) | ||
}) | ||
} | ||
|
||
private static func signalForPort(port:Int32, ipAddress:String) -> RACSignal { | ||
return RACSignal.createSignal({ (subscriber: RACSubscriber?) -> RACDisposable? in | ||
let client = TCPClient(address: ipAddress, port: port) | ||
switch client.connect(timeout: 1) { | ||
case .success: | ||
subscriber?.sendNext(String(port)) | ||
subscriber?.sendCompleted() | ||
case .failure: | ||
subscriber?.sendNext(Constants.NO_SERVICE) | ||
subscriber?.sendCompleted() | ||
} | ||
return RACDisposable(block: { | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.