public void GetLastHostAddress_HostAddress() { // arrange var inputAdr = new Ipv4Address(192, 168, 0, 1); ushort networkPortion = 26; var expected = new Ipv4Address(192, 168, 0, 62); // act var result = _manager.GetLastHostAddress(inputAdr, networkPortion); // assert Assert.NotNull(result); Assert.True(expected.ToDecimal().SequenceEqual(result.ToDecimal())); }
public string GetFullNetworkData() { var(address, networkPortion) = GetAddressAndValidNetworkPortion(); var isValid = Utils.IsLegalHostAddress(address, networkPortion); var addressType = Utils.GetAddressRange(address); var networkAddress = NetworkManager.GetNetworkAddress(address, networkPortion); var broadcastAddress = NetworkManager.GetBroadcastAddress(address, networkPortion); var firstHost = NetworkManager.GetFirstHostAddress(address, networkPortion); var lastHost = NetworkManager.GetLastHostAddress(address, networkPortion); var classOfAddress = ClassManager.GetClass(address); var possibleSubnets = ClassManager.PossibleSubnetCount(classOfAddress, networkPortion); var possibleHosts = ClassManager.PossibleHostsCount(classOfAddress, networkPortion); var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("=================== Full Network Data ==================="); sb.AppendLine(isValid ? "Host Address," : "Special Address,"); sb.AppendLine("Address type: " + addressType.Type()); sb.AppendLine("Network address: " + networkAddress.ToDecimalString()); sb.AppendLine("Broadcast address: " + broadcastAddress.ToDecimalString()); sb.AppendLine("First Host address: " + firstHost.ToDecimalString()); sb.AppendLine("Last Host address: " + lastHost.ToDecimalString()); sb.AppendLine("Possible Subnets Count: " + possibleSubnets); sb.AppendLine("Possible Hosts Count: " + possibleHosts); sb.AppendLine("========================================================="); return(sb.ToString()); }