internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterAddresses ipAdapterAddresses) { this.dnsEnabled = fixedInfo.EnableDns; this.index = ipAdapterAddresses.index; this.name = ipAdapterAddresses.AdapterName; this.ipv6Index = ipAdapterAddresses.ipv6Index; if (this.index > 0) { this.versionSupported |= IPVersion.IPv4; } if (this.ipv6Index > 0) { this.versionSupported |= IPVersion.IPv6; } this.mtu = ipAdapterAddresses.mtu; this.adapterFlags = ipAdapterAddresses.flags; this.dnsSuffix = ipAdapterAddresses.dnsSuffix; this.dynamicDnsEnabled = (ipAdapterAddresses.flags & AdapterFlags.DnsEnabled) > 0; this.multicastAddresses = SystemMulticastIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstMulticastAddress); this.dnsAddresses = SystemIPAddressInformation.ToAddressCollection(ipAdapterAddresses.FirstDnsServerAddress, this.versionSupported); this.anycastAddresses = SystemIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstAnycastAddress, this.versionSupported); this.unicastAddresses = SystemUnicastIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstUnicastAddress); if (this.ipv6Index > 0) { this.ipv6Properties = new SystemIPv6InterfaceProperties(this.ipv6Index, this.mtu); } }
// Konstruktor public STUNClient(String HostnameOrIP, int Port, TransportProtocol TransportProtocol, IPVersion IPVersion) { m_Port = Port; m_TransportProtocol = TransportProtocol; IPAddress dummy; if (IPAddress.TryParse(HostnameOrIP, out dummy)) m_IP = HostnameOrIP; else { try { IPHostEntry hostInfo = Dns.GetHostEntry(HostnameOrIP); // IPv4 if (IPVersion == STUNClient.IPVersion.IPv4) { // alle Einträge nach IPv4 Adresse durchsuchen foreach (IPAddress ip in hostInfo.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { m_IP = ip.ToString(); break; } } // falls keine IPv4 Adresse gefunden wurde if (m_IP == null) throw new Exception("Zu dem angegebenen Host konnte keine IPv4 Adresse gefunden werden"); } // andernfalls IPv6 else { // alle Einträge nach IPv6 Adresse durchsuchen foreach (IPAddress ip in hostInfo.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { m_IP = ip.ToString(); break; } } // falls keine IPv6 Adresse gefunden wurde if (m_IP == null) throw new Exception("Zu dem angegebenen Host konnte keine IPv6 Adresse gefunden werden"); } } catch (Exception e) { throw e; } } }
public static IPAddress GetLocalIPAddress(IPVersion version) { if (SharedFunctions.IPAddressRequest != null) { return SharedFunctions.IPAddressRequest(version); } else { return IPAddress.None; } }
internal static IPAddressInformationCollection ToAddressInformationCollection(IntPtr ptr, IPVersion versionSupported) { IPAddressInformationCollection informations = new IPAddressInformationCollection(); if (ptr != IntPtr.Zero) { IPEndPoint point; IpAdapterAddress adapterAddress = (IpAdapterAddress) Marshal.PtrToStructure(ptr, typeof(IpAdapterAddress)); AddressFamily family = (adapterAddress.address.addressLength > 0x10) ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork; SocketAddress socketAddress = new SocketAddress(family, adapterAddress.address.addressLength); Marshal.Copy(adapterAddress.address.address, socketAddress.m_Buffer, 0, adapterAddress.address.addressLength); if (family == AddressFamily.InterNetwork) { point = (IPEndPoint) IPEndPoint.Any.Create(socketAddress); } else { point = (IPEndPoint) IPEndPoint.IPv6Any.Create(socketAddress); } informations.InternalAdd(new SystemIPAddressInformation(adapterAddress, point.Address)); while (adapterAddress.next != IntPtr.Zero) { adapterAddress = (IpAdapterAddress) Marshal.PtrToStructure(adapterAddress.next, typeof(IpAdapterAddress)); family = (adapterAddress.address.addressLength > 0x10) ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork; if (((family == AddressFamily.InterNetwork) && ((versionSupported & IPVersion.IPv4) > IPVersion.None)) || ((family == AddressFamily.InterNetworkV6) && ((versionSupported & IPVersion.IPv6) > IPVersion.None))) { socketAddress = new SocketAddress(family, adapterAddress.address.addressLength); Marshal.Copy(adapterAddress.address.address, socketAddress.m_Buffer, 0, adapterAddress.address.addressLength); if (family == AddressFamily.InterNetwork) { point = (IPEndPoint) IPEndPoint.Any.Create(socketAddress); } else { point = (IPEndPoint) IPEndPoint.IPv6Any.Create(socketAddress); } informations.InternalAdd(new SystemIPAddressInformation(adapterAddress, point.Address)); } } } return informations; }
/// <summary> /// Get the first IP address matching the version specification (or null if no address is known so far). /// </summary> /// <param name="protocolVersion">Protocol version flag.</param> /// <returns></returns> public IPAddress GetFirstAddress(IPVersion protocolVersion) { if (false == IsResolved) return null; // If both flags are set, v6 is prefered, otherwise the specified IP version is required. IPAddress result = null; if (0 != (int)(protocolVersion & IPVersion.IPv6)) result = Addresses.Where( a => a.AddressFamily == AddressFamily.InterNetworkV6).FirstOrDefault(); if (result == null) result = Addresses.Where( a => a.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault(); if (result == null) { // no address was found although the server's addresses are already known throw new ResolverException(String.Format( "An IP address matching the version specification {0} was not found for server '{1}'.", protocolVersion.ToString(), Name)); } return result; }
internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterInfo ipAdapterInfo) { this.dnsEnabled = fixedInfo.EnableDns; this.name = ipAdapterInfo.adapterName; this.index = ipAdapterInfo.index; this.multicastAddresses = new MulticastIPAddressInformationCollection(); this.anycastAddresses = new IPAddressInformationCollection(); if (this.index > 0) { this.versionSupported |= IPVersion.IPv4; } if (ComNetOS.IsWin2K) { this.ReadRegDnsSuffix(); } this.unicastAddresses = new UnicastIPAddressInformationCollection(); foreach (IPExtendedAddress address in ipAdapterInfo.ipAddressList.ToIPExtendedAddressArrayList()) { this.unicastAddresses.InternalAdd(new SystemUnicastIPAddressInformation(ipAdapterInfo, address)); } try { this.ipv4Properties = new SystemIPv4InterfaceProperties(fixedInfo, ipAdapterInfo); if ((this.dnsAddresses == null) || (this.dnsAddresses.Count == 0)) { this.dnsAddresses = this.ipv4Properties.DnsAddresses; } } catch (NetworkInformationException exception) { if (exception.ErrorCode != 0x57L) { throw; } } }
/// <summary> /// Initializes a new instance of the <see cref="SubnetCreateDefinition"/> class. /// </summary> /// <param name="networkId">The network identifier.</param> /// <param name="ipVersion">The ip version.</param> /// <param name="cidr">The cidr.</param> public SubnetCreateDefinition(Identifier networkId, IPVersion ipVersion, string cidr) { NetworkId = networkId; IPVersion = ipVersion; CIDR = cidr; }
//internal static IEnumerable<DnsClient.DNS.Records.Address> GetAddresses(DnsDomain sname, DnsClient.Response response) //{ // IEnumerable<DnsClient.DNS.RR> rrset; // if (response.Header.AA) // { // rrset = response.AnswerRecords; // } // else // { // rrset = response.AdditionalRecords; // } // return rrset.Select<DnsClient.DNS.Records.Address>().Where( // a => sname.Equals(a.Base.NAME)); //} internal static DnsClient.DNS.QTYPE GetAddressQuestion(IPVersion ip) { switch (ip) { case IPVersion.IPv4: return DnsClient.DNS.QTYPE.A; case IPVersion.IPv6: return DnsClient.DNS.QTYPE.AAAA; default: return DnsClient.DNS.QTYPE.ANY; } }
internal AddressIterator(ResolutionIterator iterator, DnsDomain domain, IPVersion ipVersion) : base(new DomainResolver(iterator.Resolver.Options, domain), GetAddressQuestion(ipVersion), iterator.AddressCache, iterator.NestingLevel + 1) { }
internal static IpAllocationData DeserializeIpAllocationData(JsonElement element) { Optional <string> etag = default; Optional <string> id = default; Optional <string> name = default; Optional <string> type = default; Optional <string> location = default; Optional <IDictionary <string, string> > tags = default; Optional <WritableSubResource> subnet = default; Optional <WritableSubResource> virtualNetwork = default; Optional <IpAllocationType> type0 = default; Optional <string> prefix = default; Optional <int?> prefixLength = default; Optional <IPVersion> prefixType = default; Optional <string> ipamAllocationId = default; Optional <IDictionary <string, string> > allocationTags = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("id")) { id = property.Value.GetString(); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("location")) { location = property.Value.GetString(); continue; } if (property.NameEquals("tags")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("subnet")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } subnet = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("virtualNetwork")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } virtualNetwork = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("type")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } type0 = new IpAllocationType(property0.Value.GetString()); continue; } if (property0.NameEquals("prefix")) { prefix = property0.Value.GetString(); continue; } if (property0.NameEquals("prefixLength")) { if (property0.Value.ValueKind == JsonValueKind.Null) { prefixLength = null; continue; } prefixLength = property0.Value.GetInt32(); continue; } if (property0.NameEquals("prefixType")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } prefixType = new IPVersion(property0.Value.GetString()); continue; } if (property0.NameEquals("ipamAllocationId")) { ipamAllocationId = property0.Value.GetString(); continue; } if (property0.NameEquals("allocationTags")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, property1.Value.GetString()); } allocationTags = dictionary; continue; } } continue; } } return(new IpAllocationData(id.Value, name.Value, type.Value, location.Value, Optional.ToDictionary(tags), etag.Value, subnet, virtualNetwork, Optional.ToNullable(type0), prefix.Value, Optional.ToNullable(prefixLength), Optional.ToNullable(prefixType), ipamAllocationId.Value, Optional.ToDictionary(allocationTags))); }
///GENMHASH:DEFD17C7FB8B2DE605F5B8314F21538C:98C9348F48818CBA9BE5411158A7ECB2 internal NicIPConfigurationImpl WithPrivateIPVersion(IPVersion ipVersion) { Inner.PrivateIPAddressVersion = ipVersion.ToString(); return(this); }
internal static FrontendIPConfigurationData DeserializeFrontendIPConfigurationData(JsonElement element) { Optional <string> name = default; Optional <string> etag = default; Optional <string> type = default; Optional <IList <string> > zones = default; Optional <string> id = default; Optional <IReadOnlyList <WritableSubResource> > inboundNatRules = default; Optional <IReadOnlyList <WritableSubResource> > inboundNatPools = default; Optional <IReadOnlyList <WritableSubResource> > outboundRules = default; Optional <IReadOnlyList <WritableSubResource> > loadBalancingRules = default; Optional <string> privateIPAddress = default; Optional <IPAllocationMethod> privateIPAllocationMethod = default; Optional <IPVersion> privateIPAddressVersion = default; Optional <SubnetData> subnet = default; Optional <PublicIPAddressData> publicIPAddress = default; Optional <WritableSubResource> publicIPPrefix = default; Optional <WritableSubResource> gatewayLoadBalancer = default; Optional <ProvisioningState> provisioningState = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("zones")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } zones = array; continue; } if (property.NameEquals("id")) { id = property.Value.GetString(); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("inboundNatRules")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <WritableSubResource> array = new List <WritableSubResource>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(JsonSerializer.Deserialize <WritableSubResource>(item.ToString())); } inboundNatRules = array; continue; } if (property0.NameEquals("inboundNatPools")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <WritableSubResource> array = new List <WritableSubResource>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(JsonSerializer.Deserialize <WritableSubResource>(item.ToString())); } inboundNatPools = array; continue; } if (property0.NameEquals("outboundRules")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <WritableSubResource> array = new List <WritableSubResource>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(JsonSerializer.Deserialize <WritableSubResource>(item.ToString())); } outboundRules = array; continue; } if (property0.NameEquals("loadBalancingRules")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <WritableSubResource> array = new List <WritableSubResource>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(JsonSerializer.Deserialize <WritableSubResource>(item.ToString())); } loadBalancingRules = array; continue; } if (property0.NameEquals("privateIPAddress")) { privateIPAddress = property0.Value.GetString(); continue; } if (property0.NameEquals("privateIPAllocationMethod")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } privateIPAllocationMethod = new IPAllocationMethod(property0.Value.GetString()); continue; } if (property0.NameEquals("privateIPAddressVersion")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } privateIPAddressVersion = new IPVersion(property0.Value.GetString()); continue; } if (property0.NameEquals("subnet")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } subnet = SubnetData.DeserializeSubnetData(property0.Value); continue; } if (property0.NameEquals("publicIPAddress")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } publicIPAddress = PublicIPAddressData.DeserializePublicIPAddressData(property0.Value); continue; } if (property0.NameEquals("publicIPPrefix")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } publicIPPrefix = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("gatewayLoadBalancer")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } gatewayLoadBalancer = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("provisioningState")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } provisioningState = new ProvisioningState(property0.Value.GetString()); continue; } } continue; } } return(new FrontendIPConfigurationData(id.Value, name.Value, etag.Value, type.Value, Optional.ToList(zones), Optional.ToList(inboundNatRules), Optional.ToList(inboundNatPools), Optional.ToList(outboundRules), Optional.ToList(loadBalancingRules), privateIPAddress.Value, Optional.ToNullable(privateIPAllocationMethod), Optional.ToNullable(privateIPAddressVersion), subnet.Value, publicIPAddress.Value, publicIPPrefix, gatewayLoadBalancer, Optional.ToNullable(provisioningState))); }