ActiveHost constructor

ActiveHost({
  1. required InternetAddress internetAddress,
  2. List<OpenPort> openPorts = const [],
  3. String? macAddress,
  4. PingData? pingData,
  5. MdnsInfo? mdnsInfoVar,
})

Implementation

ActiveHost({
  required this.internetAddress,
  this.openPorts = const [],
  String? macAddress,
  PingData? pingData,
  MdnsInfo? mdnsInfoVar,
}) {
  _macAddress = macAddress;
  final String tempAddress = internetAddress.address;

  if (tempAddress.contains('.')) {
    hostId = tempAddress.substring(
      tempAddress.lastIndexOf('.') + 1,
      tempAddress.length,
    );
  } else if (tempAddress.contains(':')) {
    hostId = tempAddress.substring(
      tempAddress.lastIndexOf(':') + 1,
      tempAddress.length,
    );
  } else {
    hostId = '-1';
  }
  pingData ??= getPingData(tempAddress);
  _pingData = pingData;

  hostName = setHostInfo();

  // For some reason when internetAddress.host get called before the reverse
  // there is weired value
  weirdHostName = internetAddress.host;

  if (mdnsInfoVar != null) {
    mdnsInfo = Future.value(mdnsInfoVar);
  } else {
    mdnsInfo = setMdnsInfo();
  }

  deviceName = setDeviceName();

  // fetch entry from in memory arp table
  arpData = setARPData();

  // fetch vendor from in memory vendor table
  vendor = setVendor();
}