UdpScannerTask constructor

UdpScannerTask(
  1. String host,
  2. List<int> ports, {
  3. Duration socketTimeout = const Duration(milliseconds: 1000),
  4. bool shuffle = false,
  5. int parallelism = 4,
})

Creates a new instance of UdpScannerTask.

host The host to scan. ports The list of ports to scan. socketTimeout The timeout duration for the socket connection. shuffle Whether to shuffle the ports before scanning. parallelism The number of parallel isolates to use for scanning.

Implementation

UdpScannerTask(this.host, List<int> ports,
    {this.socketTimeout = const Duration(milliseconds: 1000),
    this.shuffle = false,
    int parallelism = 4}) {
  if (ports.isEmpty) {
    throw PortScannerTaskException('Ports list is empty');
  } else if (parallelism < 1) {
    throw PortScannerTaskException(
        '\'parallelism\' should be a positive number');
  } else if (ports.any((port) => port < 0 || 65535 < port)) {
    throw PortScannerTaskException('Some port is out of range 0-65535');
  }
  // Copy ports list and shuffle them if needed
  var portsList = ports.toSet().toList();
  if (shuffle) portsList.shuffle();
  this.ports = portsList;
  // Calculate number of isolates. The number of isolates can't be more than the number of ports.
  this.parallelism = min(parallelism, ports.length);
}