Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
Is it possible pinging with C# like in the CMD?

I'm trying to get IP address of a dns server with the code:

var address = Dns.GetHostAddresses(domain)[0];

Its working on my pc, but when I'm doing it through someone else pc its giving him different result (IPv6 instead of IPv4). I did try to use the method

var ipV4Address = address.MapToIPv4();

but that just returning the wrong IP address

p.s: btw, when using the command ping dns.address.blabla on both computers the result is the same.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

If the domain have IPv4 and IPv6 addresses, you'll get both. Filter by AddressFamily to InterNetwork only (IPv4) instead of InterNetworkV6 (IPv6)

var ipV4Address = Dns.GetHostAddresses(domain)
                     .First(a => a.AddressFamily == AddressFamily.InterNetwork);
over 4 years ago · Santiago Trujillo Relatório

0

To answer your specific question in the header: Yes, it is. Here's an outline of how to do that:

        using System.Net.NetworkInformation;
        ...
        private static bool PingWithResponse(int timeout, string iP, out string response)
        {
            bool result = false;

            using (var p = new Ping())
            {
                var r = p.Send(iP, timeout);

                response = $"Ping to {iP} [{r.Address}]";

                if (r.Status == IPStatus.Success)
                {
                    response += $" Successful Response delay = {r.RoundtripTime} ms";
                    result = true;
                }
                else
                {
                    response += $" Failed Status: {r.Status}";
                }
            }

            return result;
        }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda