public static IPHostEntry GetHostByName(string hostName) { if (hostName == null) { throw new ArgumentNullException("hostName"); } // // demand Unrestricted DnsPermission for this call // s_DnsPermission.Demand(); return(InternalGetHostByName(hostName, false)); }
public static IPHostEntry GetHostByName(string hostName) { if (hostName == null) { throw new ArgumentNullException("hostName"); } // // demand Unrestricted DnsPermission for this call // s_DnsPermission.Demand(); // See if it's an IP Address. IPAddress address; if (IPAddress.TryParse(hostName, out address)) { return GetUnresolveAnswer(address); } return InternalGetHostByName(hostName, false); }
static void loadAssembly1() { CodeAccessPermission permission = new DnsPermission(PermissionState.Unrestricted); try { permission.Demand(); Assembly1.Class1.openPage(); } catch (Exception ex) { Console.WriteLine(ex); } Assembly assembly = Assembly.LoadFrom("assembly1.dll"); Console.WriteLine("Strong Name : " + assembly.GetName()); }
} // NativeToHostEntry /***************************************************************************** * Function : gethostbyname * * Abstract: Queries DNS for hostname address * * Input Parameters: str (String to query) * * Returns: Void ******************************************************************************/ /// <include file='doc\DNS.uex' path='docs/doc[@for="Dns.GetHostByName"]/*' /> /// <devdoc> /// <para>Retrieves the <see cref='System.Net.IPHostEntry'/> /// information /// corresponding to the DNS name provided in the host /// parameter.</para> /// </devdoc> public static IPHostEntry GetHostByName(string hostName) { // // demand Unrestricted DnsPermission for this call // s_DnsPermission.Demand(); if (hostName == null) { throw new ArgumentNullException("hostName"); } if (hostName.Length > MaxHostName) { throw new ArgumentOutOfRangeException(SR.GetString(SR.net_toolong, "hostName", MaxHostName.ToString())); } GlobalLog.Print("Dns.GetHostByName: " + hostName); IntPtr nativePointer = UnsafeNclNativeMethods.OSSOCK.gethostbyname( hostName); if (nativePointer == IntPtr.Zero) { //This is for compatiblity with NT4 SocketException e = new SocketException(); //This block supresses "unknown error" on NT4 when input is //arbitrary IP address. It simulates same result as on Win2K. try { IPAddress address = IPAddress.Parse(hostName); IPHostEntry ipHostEntry = new IPHostEntry(); ipHostEntry.HostName = string.Copy(hostName); ipHostEntry.Aliases = new string[0]; ipHostEntry.AddressList = new IPAddress[] { address }; return(ipHostEntry); } catch { //Report original DNS error (not from IPAddress.Parse()) throw e; } } return(NativeToHostEntry(nativePointer)); } // GetHostByName
} // NativeToHostEntry /***************************************************************************** * Function : gethostbyname * * Abstract: Queries DNS for hostname address * * Input Parameters: str (String to query) * * Returns: Void ******************************************************************************/ /// <include file='doc\DNS.uex' path='docs/doc[@for="Dns.GetHostByName"]/*' /> /// <devdoc> /// <para>Retrieves the <see cref='System.Net.IPHostEntry'/> /// information /// corresponding to the DNS name provided in the host /// parameter.</para> /// </devdoc> public static IPHostEntry GetHostByName(string hostName) { // // demand Unrestricted DnsPermission for this call // s_DnsPermission.Demand(); if (hostName == null) { throw new ArgumentNullException("hostName"); } if (hostName.Length > MaxHostName) { throw new ArgumentOutOfRangeException(SR.GetString(SR.net_toolong, "hostName", MaxHostName.ToString())); } GlobalLog.Print("Dns.GetHostByName: " + hostName); // // IPv6 Changes: IPv6 requires the use of getaddrinfo() rather // than the traditional IPv4 gethostbyaddr() / gethostbyname(). // getaddrinfo() is also protocol independant in that it will also // resolve IPv4 names / addresses. As a result, it is the preferred // resolution mechanism on platforms that support it (Windows 5.1+). // If getaddrinfo() is unsupported, IPv6 resolution does not work. // // Consider : If IPv6 is disabled, we could detect IPv6 addresses // and throw an unsupported platform exception. // // Note : Whilst getaddrinfo is available on WinXP+, we only // use it if IPv6 is enabled (platform is part of that // decision). This is done to minimize the number of // possible tests that are needed. // if (Socket.SupportsIPv6) { // // IPv6 enabled: use getaddrinfo() to obtain DNS information. // return(Dns.GetAddrInfo(hostName)); } else { // // IPv6 disabled: use gethostbyname() to obtain DNS information. // IntPtr nativePointer = UnsafeNclNativeMethods.OSSOCK.gethostbyname( hostName); if (nativePointer == IntPtr.Zero) { //This is for compatiblity with NT4 SocketException e = new SocketException(); //This block supresses "unknown error" on NT4 when input is //arbitrary IP address. It simulates same result as on Win2K. try { IPAddress address = IPAddress.Parse(hostName); IPHostEntry ipHostEntry = new IPHostEntry(); ipHostEntry.HostName = string.Copy(hostName); ipHostEntry.Aliases = new string[0]; ipHostEntry.AddressList = new IPAddress[] { address }; return(ipHostEntry); } catch { //Report original DNS error (not from IPAddress.Parse()) throw e; } } return(NativeToHostEntry(nativePointer)); } } // GetHostByName