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

305
Views
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 answers
Answer question

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 Report

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 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!