514 lines
31 KiB
C#
514 lines
31 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Net.Sockets;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.Remoting.Messaging;
|
|
|
|
namespace System.Net
|
|
{
|
|
/// <summary>Provides simple domain name resolution functionality.</summary>
|
|
// Token: 0x02000212 RID: 530
|
|
public static class Dns
|
|
{
|
|
// Token: 0x06001209 RID: 4617 RVA: 0x00035F54 File Offset: 0x00034154
|
|
static Dns()
|
|
{
|
|
global::System.Net.Sockets.Socket.CheckProtocolSupport();
|
|
}
|
|
|
|
/// <summary>Begins an asynchronous request for <see cref="T:System.Net.IPHostEntry" /> information about the specified DNS host name.</summary>
|
|
/// <returns>An <see cref="T:System.IAsyncResult" /> instance that references the asynchronous request.</returns>
|
|
/// <param name="hostName">The DNS name of the host. </param>
|
|
/// <param name="requestCallback">An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.</param>
|
|
/// <param name="stateObject">A user-defined object that contains information about the operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="hostName" /> is null. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error was encountered executing the DNS query. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600120A RID: 4618 RVA: 0x00035F5C File Offset: 0x0003415C
|
|
[Obsolete("Use BeginGetHostEntry instead")]
|
|
public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback requestCallback, object stateObject)
|
|
{
|
|
if (hostName == null)
|
|
{
|
|
throw new ArgumentNullException("hostName");
|
|
}
|
|
Dns.GetHostByNameCallback getHostByNameCallback = new Dns.GetHostByNameCallback(Dns.GetHostByName);
|
|
return getHostByNameCallback.BeginInvoke(hostName, requestCallback, stateObject);
|
|
}
|
|
|
|
/// <summary>Begins an asynchronous request to resolve a DNS host name or IP address to an <see cref="T:System.Net.IPAddress" /> instance.</summary>
|
|
/// <returns>An <see cref="T:System.IAsyncResult" /> instance that references the asynchronous request.</returns>
|
|
/// <param name="hostName">The DNS name of the host. </param>
|
|
/// <param name="requestCallback">An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete. </param>
|
|
/// <param name="stateObject">A user-defined object that contains information about the operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="hostName" /> is null. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">The caller does not have permission to access DNS information. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600120B RID: 4619 RVA: 0x00035F90 File Offset: 0x00034190
|
|
[Obsolete("Use BeginGetHostEntry instead")]
|
|
public static IAsyncResult BeginResolve(string hostName, AsyncCallback requestCallback, object stateObject)
|
|
{
|
|
if (hostName == null)
|
|
{
|
|
throw new ArgumentNullException("hostName");
|
|
}
|
|
Dns.ResolveCallback resolveCallback = new Dns.ResolveCallback(Dns.Resolve);
|
|
return resolveCallback.BeginInvoke(hostName, requestCallback, stateObject);
|
|
}
|
|
|
|
/// <summary>Asynchronously returns the Internet Protocol (IP) addresses for the specified host.</summary>
|
|
/// <returns>An <see cref="T:System.IAsyncResult" /> instance that references the asynchronous request.</returns>
|
|
/// <param name="hostNameOrAddress">The host name or IP address to resolve.</param>
|
|
/// <param name="requestCallback">An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete. </param>
|
|
/// <param name="state">A user-defined object that contains information about the operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="hostNameOrAddress" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The length of <paramref name="hostNameOrAddress" /> is greater than 126 characters. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="hostNameOrAddress" />. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="hostNameOrAddress" /> is an invalid IP address.</exception>
|
|
// Token: 0x0600120C RID: 4620 RVA: 0x00035FC4 File Offset: 0x000341C4
|
|
public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, AsyncCallback requestCallback, object stateObject)
|
|
{
|
|
if (hostNameOrAddress == null)
|
|
{
|
|
throw new ArgumentNullException("hostName");
|
|
}
|
|
if (hostNameOrAddress == "0.0.0.0" || hostNameOrAddress == "::0")
|
|
{
|
|
throw new ArgumentException("Addresses 0.0.0.0 (IPv4) and ::0 (IPv6) are unspecified addresses. You cannot use them as target address.", "hostNameOrAddress");
|
|
}
|
|
Dns.GetHostAddressesCallback getHostAddressesCallback = new Dns.GetHostAddressesCallback(Dns.GetHostAddresses);
|
|
return getHostAddressesCallback.BeginInvoke(hostNameOrAddress, requestCallback, stateObject);
|
|
}
|
|
|
|
/// <summary>Asynchronously resolves a host name or IP address to an <see cref="T:System.Net.IPHostEntry" /> instance.</summary>
|
|
/// <returns>An <see cref="T:System.IAsyncResult" /> instance that references the asynchronous request.</returns>
|
|
/// <param name="hostNameOrAddress">The host name or IP address to resolve.</param>
|
|
/// <param name="requestCallback">An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete. </param>
|
|
/// <param name="stateObject">A user-defined object that contains information about the operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="hostNameOrAddress" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The length of <paramref name="hostNameOrAddress" /> is greater than 126 characters. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="hostNameOrAddress" />. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="hostNameOrAddress" /> is an invalid IP address.</exception>
|
|
// Token: 0x0600120D RID: 4621 RVA: 0x00036028 File Offset: 0x00034228
|
|
public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCallback requestCallback, object stateObject)
|
|
{
|
|
if (hostNameOrAddress == null)
|
|
{
|
|
throw new ArgumentNullException("hostName");
|
|
}
|
|
if (hostNameOrAddress == "0.0.0.0" || hostNameOrAddress == "::0")
|
|
{
|
|
throw new ArgumentException("Addresses 0.0.0.0 (IPv4) and ::0 (IPv6) are unspecified addresses. You cannot use them as target address.", "hostNameOrAddress");
|
|
}
|
|
Dns.GetHostEntryNameCallback getHostEntryNameCallback = new Dns.GetHostEntryNameCallback(Dns.GetHostEntry);
|
|
return getHostEntryNameCallback.BeginInvoke(hostNameOrAddress, requestCallback, stateObject);
|
|
}
|
|
|
|
/// <summary>Asynchronously resolves an IP address to an <see cref="T:System.Net.IPHostEntry" /> instance.</summary>
|
|
/// <returns>An <see cref="T:System.IAsyncResult" /> instance that references the asynchronous request.</returns>
|
|
/// <param name="address">The IP address to resolve.</param>
|
|
/// <param name="requestCallback">An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete. </param>
|
|
/// <param name="stateObject">A user-defined object that contains information about the operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="address" /> is null. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="address" />. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="address" /> is an invalid IP address.</exception>
|
|
// Token: 0x0600120E RID: 4622 RVA: 0x0003608C File Offset: 0x0003428C
|
|
public static IAsyncResult BeginGetHostEntry(IPAddress address, AsyncCallback requestCallback, object stateObject)
|
|
{
|
|
if (address == null)
|
|
{
|
|
throw new ArgumentNullException("address");
|
|
}
|
|
Dns.GetHostEntryIPCallback getHostEntryIPCallback = new Dns.GetHostEntryIPCallback(Dns.GetHostEntry);
|
|
return getHostEntryIPCallback.BeginInvoke(address, requestCallback, stateObject);
|
|
}
|
|
|
|
/// <summary>Ends an asynchronous request for DNS information.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> object that contains DNS information about a host.</returns>
|
|
/// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> instance that is returned by a call to the <see cref="M:System.Net.Dns.BeginGetHostByName(System.String,System.AsyncCallback,System.Object)" /> method.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="asyncResult" /> is null. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600120F RID: 4623 RVA: 0x000360C0 File Offset: 0x000342C0
|
|
[Obsolete("Use EndGetHostEntry instead")]
|
|
public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult)
|
|
{
|
|
if (asyncResult == null)
|
|
{
|
|
throw new ArgumentNullException("asyncResult");
|
|
}
|
|
AsyncResult asyncResult2 = (AsyncResult)asyncResult;
|
|
Dns.GetHostByNameCallback getHostByNameCallback = (Dns.GetHostByNameCallback)asyncResult2.AsyncDelegate;
|
|
return getHostByNameCallback.EndInvoke(asyncResult);
|
|
}
|
|
|
|
/// <summary>Ends an asynchronous request for DNS information.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> object that contains DNS information about a host.</returns>
|
|
/// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> instance that is returned by a call to the <see cref="M:System.Net.Dns.BeginResolve(System.String,System.AsyncCallback,System.Object)" /> method.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="asyncResult" /> is null. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x06001210 RID: 4624 RVA: 0x000360F8 File Offset: 0x000342F8
|
|
[Obsolete("Use EndGetHostEntry instead")]
|
|
public static IPHostEntry EndResolve(IAsyncResult asyncResult)
|
|
{
|
|
if (asyncResult == null)
|
|
{
|
|
throw new ArgumentNullException("asyncResult");
|
|
}
|
|
AsyncResult asyncResult2 = (AsyncResult)asyncResult;
|
|
Dns.ResolveCallback resolveCallback = (Dns.ResolveCallback)asyncResult2.AsyncDelegate;
|
|
return resolveCallback.EndInvoke(asyncResult);
|
|
}
|
|
|
|
/// <summary>Ends an asynchronous request for DNS information.</summary>
|
|
/// <returns>An array of type <see cref="T:System.Net.IPAddress" /> that holds the IP addresses for the host specified by the <paramref name="hostNameOrAddress" /> parameter of <see cref="M:System.Net.Dns.BeginGetHostAddresses(System.String,System.AsyncCallback,System.Object)" />.</returns>
|
|
/// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> instance returned by a call to the <see cref="M:System.Net.Dns.BeginGetHostAddresses(System.String,System.AsyncCallback,System.Object)" /> method.</param>
|
|
// Token: 0x06001211 RID: 4625 RVA: 0x00036130 File Offset: 0x00034330
|
|
public static IPAddress[] EndGetHostAddresses(IAsyncResult asyncResult)
|
|
{
|
|
if (asyncResult == null)
|
|
{
|
|
throw new ArgumentNullException("asyncResult");
|
|
}
|
|
AsyncResult asyncResult2 = (AsyncResult)asyncResult;
|
|
Dns.GetHostAddressesCallback getHostAddressesCallback = (Dns.GetHostAddressesCallback)asyncResult2.AsyncDelegate;
|
|
return getHostAddressesCallback.EndInvoke(asyncResult);
|
|
}
|
|
|
|
/// <summary>Ends an asynchronous request for DNS information.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> instance that contains address information about the host.</returns>
|
|
/// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> instance returned by a call to an <see cref="Overload:System.Net.Dns.BeginGetHostEntry" /> method.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="asyncResult" /> is null. </exception>
|
|
// Token: 0x06001212 RID: 4626 RVA: 0x00036168 File Offset: 0x00034368
|
|
public static IPHostEntry EndGetHostEntry(IAsyncResult asyncResult)
|
|
{
|
|
if (asyncResult == null)
|
|
{
|
|
throw new ArgumentNullException("asyncResult");
|
|
}
|
|
AsyncResult asyncResult2 = (AsyncResult)asyncResult;
|
|
if (asyncResult2.AsyncDelegate is Dns.GetHostEntryIPCallback)
|
|
{
|
|
return ((Dns.GetHostEntryIPCallback)asyncResult2.AsyncDelegate).EndInvoke(asyncResult);
|
|
}
|
|
Dns.GetHostEntryNameCallback getHostEntryNameCallback = (Dns.GetHostEntryNameCallback)asyncResult2.AsyncDelegate;
|
|
return getHostEntryNameCallback.EndInvoke(asyncResult);
|
|
}
|
|
|
|
// Token: 0x06001213 RID: 4627
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern bool GetHostByName_internal(string host, out string h_name, out string[] h_aliases, out string[] h_addr_list);
|
|
|
|
// Token: 0x06001214 RID: 4628
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern bool GetHostByAddr_internal(string addr, out string h_name, out string[] h_aliases, out string[] h_addr_list);
|
|
|
|
// Token: 0x06001215 RID: 4629
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern bool GetHostName_internal(out string h_name);
|
|
|
|
// Token: 0x06001216 RID: 4630 RVA: 0x000361C4 File Offset: 0x000343C4
|
|
private static IPHostEntry hostent_to_IPHostEntry(string h_name, string[] h_aliases, string[] h_addrlist)
|
|
{
|
|
IPHostEntry iphostEntry = new IPHostEntry();
|
|
ArrayList arrayList = new ArrayList();
|
|
iphostEntry.HostName = h_name;
|
|
iphostEntry.Aliases = h_aliases;
|
|
for (int i = 0; i < h_addrlist.Length; i++)
|
|
{
|
|
try
|
|
{
|
|
IPAddress ipaddress = IPAddress.Parse(h_addrlist[i]);
|
|
if ((global::System.Net.Sockets.Socket.SupportsIPv6 && ipaddress.AddressFamily == global::System.Net.Sockets.AddressFamily.InterNetworkV6) || (global::System.Net.Sockets.Socket.SupportsIPv4 && ipaddress.AddressFamily == global::System.Net.Sockets.AddressFamily.InterNetwork))
|
|
{
|
|
arrayList.Add(ipaddress);
|
|
}
|
|
}
|
|
catch (ArgumentNullException)
|
|
{
|
|
}
|
|
}
|
|
if (arrayList.Count == 0)
|
|
{
|
|
throw new global::System.Net.Sockets.SocketException(11001);
|
|
}
|
|
iphostEntry.AddressList = arrayList.ToArray(typeof(IPAddress)) as IPAddress[];
|
|
return iphostEntry;
|
|
}
|
|
|
|
/// <summary>Creates an <see cref="T:System.Net.IPHostEntry" /> instance from the specified <see cref="T:System.Net.IPAddress" />.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" />.</returns>
|
|
/// <param name="address">An <see cref="T:System.Net.IPAddress" />. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="address" /> is null. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="address" />. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x06001217 RID: 4631 RVA: 0x00036298 File Offset: 0x00034498
|
|
[Obsolete("Use GetHostEntry instead")]
|
|
public static IPHostEntry GetHostByAddress(IPAddress address)
|
|
{
|
|
if (address == null)
|
|
{
|
|
throw new ArgumentNullException("address");
|
|
}
|
|
return Dns.GetHostByAddressFromString(address.ToString(), false);
|
|
}
|
|
|
|
/// <summary>Creates an <see cref="T:System.Net.IPHostEntry" /> instance from an IP address.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> instance.</returns>
|
|
/// <param name="address">An IP address. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="address" /> is null. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="address" />. </exception>
|
|
/// <exception cref="T:System.FormatException">
|
|
/// <paramref name="address" /> is not a valid IP address. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x06001218 RID: 4632 RVA: 0x000362B8 File Offset: 0x000344B8
|
|
[Obsolete("Use GetHostEntry instead")]
|
|
public static IPHostEntry GetHostByAddress(string address)
|
|
{
|
|
if (address == null)
|
|
{
|
|
throw new ArgumentNullException("address");
|
|
}
|
|
return Dns.GetHostByAddressFromString(address, true);
|
|
}
|
|
|
|
// Token: 0x06001219 RID: 4633 RVA: 0x000362D4 File Offset: 0x000344D4
|
|
private static IPHostEntry GetHostByAddressFromString(string address, bool parse)
|
|
{
|
|
if (address.Equals("0.0.0.0"))
|
|
{
|
|
address = "127.0.0.1";
|
|
parse = false;
|
|
}
|
|
if (parse)
|
|
{
|
|
IPAddress.Parse(address);
|
|
}
|
|
string text;
|
|
string[] array;
|
|
string[] array2;
|
|
if (!Dns.GetHostByAddr_internal(address, out text, out array, out array2))
|
|
{
|
|
throw new global::System.Net.Sockets.SocketException(11001);
|
|
}
|
|
return Dns.hostent_to_IPHostEntry(text, array, array2);
|
|
}
|
|
|
|
/// <summary>Resolves a host name or IP address to an <see cref="T:System.Net.IPHostEntry" /> instance.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> instance that contains address information about the host specified in <paramref name="hostNameOrAddress" />.</returns>
|
|
/// <param name="hostNameOrAddress">The host name or IP address to resolve.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="hostNameOrAddress" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The length of <paramref name="hostNameOrAddress" /> parameter is greater than 126 characters. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error was encountered when resolving the <paramref name="hostNameOrAddress" /> parameter. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="hostNameOrAddress" /> parameter is an invalid IP address. </exception>
|
|
// Token: 0x0600121A RID: 4634 RVA: 0x00036330 File Offset: 0x00034530
|
|
public static IPHostEntry GetHostEntry(string hostNameOrAddress)
|
|
{
|
|
if (hostNameOrAddress == null)
|
|
{
|
|
throw new ArgumentNullException("hostNameOrAddress");
|
|
}
|
|
if (hostNameOrAddress == "0.0.0.0" || hostNameOrAddress == "::0")
|
|
{
|
|
throw new ArgumentException("Addresses 0.0.0.0 (IPv4) and ::0 (IPv6) are unspecified addresses. You cannot use them as target address.", "hostNameOrAddress");
|
|
}
|
|
IPAddress ipaddress;
|
|
if (hostNameOrAddress.Length > 0 && IPAddress.TryParse(hostNameOrAddress, out ipaddress))
|
|
{
|
|
return Dns.GetHostEntry(ipaddress);
|
|
}
|
|
return Dns.GetHostByName(hostNameOrAddress);
|
|
}
|
|
|
|
/// <summary>Resolves an IP address to an <see cref="T:System.Net.IPHostEntry" /> instance.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> instance that contains address information about the host specified in <paramref name="address" />.</returns>
|
|
/// <param name="address">An IP address.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="address" /> is null. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="address" />. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="address" /> is an invalid IP address.</exception>
|
|
// Token: 0x0600121B RID: 4635 RVA: 0x000363A4 File Offset: 0x000345A4
|
|
public static IPHostEntry GetHostEntry(IPAddress address)
|
|
{
|
|
if (address == null)
|
|
{
|
|
throw new ArgumentNullException("address");
|
|
}
|
|
return Dns.GetHostByAddressFromString(address.ToString(), false);
|
|
}
|
|
|
|
/// <summary>Returns the Internet Protocol (IP) addresses for the specified host.</summary>
|
|
/// <returns>An array of type <see cref="T:System.Net.IPAddress" /> that holds the IP addresses for the host that is specified by the <paramref name="hostNameOrAddress" /> parameter.</returns>
|
|
/// <param name="hostNameOrAddress">The host name or IP address to resolve.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="hostNameOrAddress" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The length of <paramref name="hostNameOrAddress" /> is greater than 126 characters. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="hostNameOrAddress" />. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="hostNameOrAddress" /> is an invalid IP address.</exception>
|
|
// Token: 0x0600121C RID: 4636 RVA: 0x000363C4 File Offset: 0x000345C4
|
|
public static IPAddress[] GetHostAddresses(string hostNameOrAddress)
|
|
{
|
|
if (hostNameOrAddress == null)
|
|
{
|
|
throw new ArgumentNullException("hostNameOrAddress");
|
|
}
|
|
if (hostNameOrAddress == "0.0.0.0" || hostNameOrAddress == "::0")
|
|
{
|
|
throw new ArgumentException("Addresses 0.0.0.0 (IPv4) and ::0 (IPv6) are unspecified addresses. You cannot use them as target address.", "hostNameOrAddress");
|
|
}
|
|
IPAddress ipaddress;
|
|
if (hostNameOrAddress.Length > 0 && IPAddress.TryParse(hostNameOrAddress, out ipaddress))
|
|
{
|
|
return new IPAddress[] { ipaddress };
|
|
}
|
|
return Dns.GetHostEntry(hostNameOrAddress).AddressList;
|
|
}
|
|
|
|
/// <summary>Gets the DNS information for the specified DNS host name.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> object that contains host information for the address specified in <paramref name="hostName" />.</returns>
|
|
/// <param name="hostName">The DNS name of the host. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="hostName" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The length of <paramref name="hostName" /> is greater than 126 characters. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="hostName" />. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600121D RID: 4637 RVA: 0x00036444 File Offset: 0x00034644
|
|
[Obsolete("Use GetHostEntry instead")]
|
|
public static IPHostEntry GetHostByName(string hostName)
|
|
{
|
|
if (hostName == null)
|
|
{
|
|
throw new ArgumentNullException("hostName");
|
|
}
|
|
string text;
|
|
string[] array;
|
|
string[] array2;
|
|
if (!Dns.GetHostByName_internal(hostName, out text, out array, out array2))
|
|
{
|
|
throw new global::System.Net.Sockets.SocketException(11001);
|
|
}
|
|
return Dns.hostent_to_IPHostEntry(text, array, array2);
|
|
}
|
|
|
|
/// <summary>Gets the host name of the local computer.</summary>
|
|
/// <returns>A string that contains the DNS host name of the local computer.</returns>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving the local host name. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600121E RID: 4638 RVA: 0x00036488 File Offset: 0x00034688
|
|
public static string GetHostName()
|
|
{
|
|
string text;
|
|
if (!Dns.GetHostName_internal(out text))
|
|
{
|
|
throw new global::System.Net.Sockets.SocketException(11001);
|
|
}
|
|
return text;
|
|
}
|
|
|
|
/// <summary>Resolves a DNS host name or IP address to an <see cref="T:System.Net.IPHostEntry" /> instance.</summary>
|
|
/// <returns>An <see cref="T:System.Net.IPHostEntry" /> instance that contains address information about the host specified in <paramref name="hostName" />.</returns>
|
|
/// <param name="hostName">A DNS-style host name or IP address. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="hostName" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The length of <paramref name="hostName" /> is greater than 126 characters. </exception>
|
|
/// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="hostName" />. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600121F RID: 4639 RVA: 0x000364B0 File Offset: 0x000346B0
|
|
[Obsolete("Use GetHostEntry instead")]
|
|
public static IPHostEntry Resolve(string hostName)
|
|
{
|
|
if (hostName == null)
|
|
{
|
|
throw new ArgumentNullException("hostName");
|
|
}
|
|
IPHostEntry iphostEntry = null;
|
|
try
|
|
{
|
|
iphostEntry = Dns.GetHostByAddress(hostName);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
if (iphostEntry == null)
|
|
{
|
|
iphostEntry = Dns.GetHostByName(hostName);
|
|
}
|
|
return iphostEntry;
|
|
}
|
|
|
|
// Token: 0x02000310 RID: 784
|
|
// (Invoke) Token: 0x06001C19 RID: 7193
|
|
private delegate IPHostEntry GetHostByNameCallback(string hostName);
|
|
|
|
// Token: 0x02000311 RID: 785
|
|
// (Invoke) Token: 0x06001C1D RID: 7197
|
|
private delegate IPHostEntry ResolveCallback(string hostName);
|
|
|
|
// Token: 0x02000312 RID: 786
|
|
// (Invoke) Token: 0x06001C21 RID: 7201
|
|
private delegate IPHostEntry GetHostEntryNameCallback(string hostName);
|
|
|
|
// Token: 0x02000313 RID: 787
|
|
// (Invoke) Token: 0x06001C25 RID: 7205
|
|
private delegate IPHostEntry GetHostEntryIPCallback(IPAddress hostAddress);
|
|
|
|
// Token: 0x02000314 RID: 788
|
|
// (Invoke) Token: 0x06001C29 RID: 7209
|
|
private delegate IPAddress[] GetHostAddressesCallback(string hostName);
|
|
}
|
|
}
|