public static bool TryParse(string text, out IPAddress address) { address = null; if (String.IsNullOrWhiteSpace(text)) { return false; } var segments = text.Split('.'); var addressBytes = new byte[4]; if (segments.Length == 3) { if (!ExtractThreeSegments(addressBytes, segments)) { return false; } } else if (segments.Length == 4) { if (!ExtractFourSegments(addressBytes, segments)) { return false; } } else { return false; } address = new IPAddress(addressBytes); return true; }
public IPNetwork(uint value, byte prefixLength) { if (!IPNetworkHelper.IsValidNetworkPrefixLength(prefixLength)) { throw new ArgumentOutOfRangeException("prefixLength"); } m_prefixLength = prefixLength; // TODO: Consider moving GetNetworkMaskValue into constructor IPNetworkMask since we now have a separate class for it... m_networkMask = new IPNetworkMask(IPNetworkHelper.GetNetworkMaskValue(m_prefixLength)); m_networkAddressValue = value & m_networkMask.Value; m_networkAddress = new IPAddress(m_networkAddressValue); if (m_prefixLength < 32) { m_firstUsableAddress = new IPAddress(m_networkAddressValue + 1); var wildcardMask = 0xffffffff - m_networkMask.Value; var broadcastAddressValue = m_networkAddressValue | wildcardMask; m_lastUsableAddress = new IPAddress(broadcastAddressValue - 1); m_broadcastAddress = new IPAddress(broadcastAddressValue); m_usableAddresses = new IPAddressRange(m_firstUsableAddress, m_lastUsableAddress); } else { m_usableAddresses = IPAddressRange.Empty; } }
public IPEndpoint(IPAddress address, ushort port) { if (address == null) { throw new ArgumentNullException("address"); } m_address = address; m_port = port; m_serviceName = m_port.ToString(CultureInfo.InvariantCulture); }
public ConnectionInfo(IPAddress address, IPNetwork network) { if (address == null) { throw new ArgumentNullException("address"); } if (network == null) { throw new ArgumentNullException("network"); } m_address = address; m_network = network; }
public DhcpInfo(IPAddress gatewayAddress, IPAddress dnsServerAddress, string domainName) { if (gatewayAddress == null) { throw new ArgumentNullException("gatewayAddress"); } if (dnsServerAddress == null) { throw new ArgumentNullException("dnsServerAddress"); } m_gatewayAddress = gatewayAddress; m_dnsServerAddress = dnsServerAddress; m_domainName = domainName; }
public HostInfo(Guid networkAdapterId, HostName hostName, IPAddress address) { if (hostName == null) { throw new ArgumentNullException("hostName"); } if (address == null) { throw new ArgumentNullException("address"); } m_networkAdapterId = networkAdapterId; m_hostName = hostName; m_address = address; }
public IPHostEntry(string hostName, IPAddress[] addresses, string[] aliases) { if (string.IsNullOrWhiteSpace(hostName)) { throw new ArgumentException("Invalid host name", "hostName"); } if (addresses == null) { throw new ArgumentNullException("addresses"); } if (aliases == null) { throw new ArgumentNullException("aliases"); } m_hostName = hostName; m_addresses = addresses; m_aliases = aliases; }
private static IPAddress GetAddress(IntPtr data, int offset = 0) { var addressBytes = (DHCPCAPI_IP_ADDRESS)Marshal.PtrToStructure(data + offset, typeof(DHCPCAPI_IP_ADDRESS)); var result = new IPAddress(new[] { addressBytes.Value0, addressBytes.Value1, addressBytes.Value2, addressBytes.Value3 }); return result; }
private static IPAddress[] GetAddresses(IntPtr data, int addressCount) { var addresses = new IPAddress[addressCount]; for (int i = 0, offset = 0; i < addressCount; ++i, offset += 4) { addresses[i] = GetAddress(data, offset); } return addresses; }
public IPNetwork(IPAddress networkAddress, byte prefixLength) : this(GetAddressValue(networkAddress), prefixLength) { }
private static uint GetAddressValue(IPAddress networkAddress) { if (networkAddress == null) { throw new ArgumentNullException("networkAddress"); } var result = networkAddress.Value; return result; }