Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
¿Es posible hacer ping con C# como en el CMD?

Estoy tratando de obtener la dirección IP de un servidor dns con el código:

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

Está funcionando en mi PC, pero cuando lo hago a través de otra PC, le da un resultado diferente (IPv6 en lugar de IPv4). Intenté usar el método

 var ipV4Address = address.MapToIPv4();

pero eso solo devuelve la dirección IP incorrecta

pd: por cierto, al usar el comando ping dns.address.blabla en ambas computadoras, el resultado es el mismo.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si el dominio tiene direcciones IPv4 e IPv6, obtendrá ambas. Filtrar por AddressFamily a InterNetwork solamente (IPv4) en lugar de InterNetworkV6 (IPv6)

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

0

Para responder a su pregunta específica en el encabezado: Sí, lo es. Aquí hay un esquema de cómo hacerlo:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!