none
No such host is known error RRS feed

  • Question

  • Hi,

    Why I get No such host is known for this IP: 151.101.64.81

    This is the exact error:

    System.Net.Sockets.SocketException
      HResult=0x80004005
      Message=No such host is known
      Source=System
      StackTrace:
       at System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6)
       at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
       at WindowsFormsApp1.Form1.PingTo(String id, String address) in C:\Users\jrahm\Source\Repos\WindowsFormsApp1\WindowsFormsApp1\Form1.cs:line 277
       at WindowsFormsApp1.Form1.<BtnPing_ClickAsync>b__27_0() in C:\Users\jrahm\Source\Repos\WindowsFormsApp1\WindowsFormsApp1\Form1.cs:line 233
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()

    and this is the code:

    private void PingTo(string id, string address)
    {
        txtPingResult.AppendText("Started Pinging " + address + " [ID: " + id + "]");
    
        Ping pingSender = new Ping();
    
        PingOptions options = new PingOptions(64, true);
    
        options.DontFragment = true;
    
        // Create a buffer of 32 bytes of data to be transmitted.
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = Encoding.ASCII.GetBytes(data);
        int timeout = 120;
    
        IPAddress ip_host = IPAddress.Parse(address);
    
        PingReply reply = pingSender.Send(ip_host, timeout, buffer, options);
    
        if (reply.Status == IPStatus.Success)
        {
            IPHostEntry hostEntry = Dns.GetHostEntry(address);
    
            txtPingResult.AppendText(hostEntry.HostName);
            txtPingResult.AppendText(Environment.NewLine);
            txtPingResult.AppendText("Address: " + reply.Address.ToString());
            txtPingResult.AppendText(Environment.NewLine);
            txtPingResult.AppendText("RoundTrip time: " + reply.RoundtripTime);
            txtPingResult.AppendText(Environment.NewLine);
            txtPingResult.AppendText(Environment.NewLine);
        }
        else
        {
            txtPingResult.AppendText("Failed Pinging..");
        }
    
        txtPingResult.AppendText("Finished Pinging " + address + " [ID: " + id + "]");
        txtPingResult.AppendText("--------------------------------------");
        txtPingResult.AppendText(Environment.NewLine);
    }
    

    Thanks,

    Jassim

    Wednesday, July 24, 2019 5:48 PM

All replies

  • Hi Jassim Rahma, 

    Thank you for posting here.

    Based on your code, I use my local IP address to do the test.

    Result of my test:

    I don’t get the error, so your IP address may be wrong.

    Please check your IP address.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 25, 2019 9:40 AM
    Moderator
  • but that's the IP which throws an error:

    151.101.64.81

    and it's pingable

    

    Thursday, July 25, 2019 4:46 PM
  • Hi Jassim Rahma, 

    Thanks for your feedback.

    A successful Ping indicates only that the remote host can be reached on the network; the presence of higher level services (such as a Web server) on the remote host is not guaranteed.

    You can use the following code to find IP address.

            public static string GetIpAddress()
            {
                UnicastIPAddressInformation mostSuitableIp = null;
    
                var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
    
                foreach (var network in networkInterfaces)
                {
                    if (network.OperationalStatus != OperationalStatus.Up)
                        continue;
    
                    var properties = network.GetIPProperties();
    
                    if (properties.GatewayAddresses.Count == 0)
                        continue;
    
                    foreach (var address in properties.UnicastAddresses)
                    {
                        if (address.Address.AddressFamily != AddressFamily.InterNetwork)
                            continue;
    
                        if (IPAddress.IsLoopback(address.Address))
                            continue;
    
                        if (!address.IsDnsEligible)
                        {
                            if (mostSuitableIp == null)
                                mostSuitableIp = address;
                            continue;
                        }
    
                        // The best IP is the IP got from DHCP server
                        if (address.PrefixOrigin != PrefixOrigin.Dhcp)
                        {
                            if (mostSuitableIp == null || !mostSuitableIp.IsDnsEligible)
                                mostSuitableIp = address;
                            continue;
                        }
    
                        return address.Address.ToString();
                    }
                }
    
                return mostSuitableIp != null
                    ? mostSuitableIp.Address.ToString()
                    : "";
            }

    Besides, you can enter 'ipconfig' in Command Prompt to find all IP addresses.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 26, 2019 9:29 AM
    Moderator