Line data Source code
1 : import 'dart:async';
2 :
3 : import 'package:network_tools/network_tools.dart';
4 :
5 : /// Scans open port for a target Address or domain.
6 : abstract class PortScannerService {
7 1 : PortScannerService() {
8 : _instance = this;
9 : }
10 :
11 1 : static late PortScannerService _instance;
12 :
13 2 : static PortScannerService get instance => _instance;
14 :
15 : static const int defaultStartPort = 1;
16 : static const int defaultEndPort = 1024;
17 :
18 : static const List<int> commonPorts = [
19 : 20,
20 : 21,
21 : 22,
22 : 23,
23 : 25,
24 : 50,
25 : 51,
26 : 53,
27 : 67,
28 : 68,
29 : 69,
30 : 80,
31 : 110,
32 : 119,
33 : 123,
34 : 135,
35 : 139,
36 : 143,
37 : 161,
38 : 162,
39 : 389,
40 : 443,
41 : 989,
42 : 990,
43 : 3389,
44 : ];
45 :
46 : /// Checks if the single [port] is open or not for the [target].
47 : Future<ActiveHost?> isOpen(
48 : String target,
49 : int port, {
50 : Duration timeout = const Duration(milliseconds: 2000),
51 : });
52 :
53 : /// Scans ports only listed in [portList] for a [target]. Progress can be
54 : /// retrieved by [progressCallback]
55 : /// Tries connecting ports before until [timeout] reached.
56 : /// [resultsInAddressAscendingOrder] = false will return results faster but not in
57 : /// ascending order and without [progressCallback].
58 : Stream<ActiveHost> customDiscover(
59 : String target, {
60 : List<int> portList = commonPorts,
61 : ProgressCallback? progressCallback,
62 : Duration timeout = const Duration(milliseconds: 2000),
63 : bool resultsInAddressAscendingOrder = true,
64 : bool async = false,
65 : });
66 :
67 : /// Scans port from [startPort] to [endPort] of [target]. Progress can be
68 : /// retrieved by [progressCallback]
69 : /// Tries connecting ports before until [timeout] reached.
70 : Stream<ActiveHost> scanPortsForSingleDevice(
71 : String target, {
72 : int startPort = defaultStartPort,
73 : int endPort = defaultEndPort,
74 : ProgressCallback? progressCallback,
75 : Duration timeout = const Duration(milliseconds: 2000),
76 : bool resultsInAddressAscendingOrder = true,
77 : bool async = false,
78 : });
79 :
80 : Future<ActiveHost?> connectToPort({
81 : required String address,
82 : required int port,
83 : required Duration timeout,
84 : required StreamController<ActiveHost> activeHostsController,
85 : int recursionCount = 0,
86 : });
87 : }
|