Find Device HostName and Ipv4 address



    Kenan Yusubov

    The code first retrieves the hostname from the DNS server. It then loops through the array of IP addresses found in the retrieved hostname. For each IP address, it checks to see if the IP address is of the InterNetwork type. If it is, it prints out the IP address and then terminates the loop.

    using System.Net;
    using System.Net.Sockets;
    var host = Dns.GetHostEntry(Dns.GetHostName());
      foreach (var ip in host.AddressList)
        if (ip.AddressFamily == AddressFamily.InterNetwork)
          // Get Ipv4 Address
      // Get the Name of HOST  
      string hostName = Dns.GetHostName();
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.