0

How to get IP Address which has DNS (Specified)?, because it connected to specific domain network. Which i can view in command prompt using command "ipconfig /all"

Seperately i can retrieve the DNS server and its IP Addresses, HostName and its IP Addresses.

I would like to get the IP Address of hostmachine which has the DNS server name.

Code used,

string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
if (domainName == "oogway.net")
{
        //IP Address of hostmachine
}

Image reference about to get IP of domain name:

IP Address of domain name


I want to get only this IP address which is connected to network. Other VM IP Addresses are my machine which does not has domain name "oogway.net"

Image reference Other IP in same machine: Other IP in same machine


Thanks

SHR
  • 7,940
  • 9
  • 38
  • 57

1 Answers1

0

Have a look,it's a way to get those values but it's a custom method which you have made choice for your own way as you want,

  • Create Batch File with Name file.bat and write ipconfig /all command inside it.
  • Make the Process of std out for getting output string from batch file to run it programmatically.After that,you will get string of output and split it for finding IPv4,Mac etc as showing you, following code to be tested.But you can customize for your own better choice.

        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "file.bat";
        p.Start();
        string output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();
        string[] splits = output.Split('\n');
        List<string> results = new List<string>();
        foreach (string s in splits)
        {
            var twoParts = s.Split(':');
            if (twoParts.Length == 2)
            {
                //Here you will apply checks for IP address and other mac etc
                //after that add those values to result list and get on last
                if (twoParts[0].Contains("IPv4"))
                    results.Add(twoParts[1]);
                else if (twoParts[0].Contains("Physical"))
                    results.Add(twoParts[1]);
                else if (twoParts[0].Contains("DNS"))
                    results.Add(twoParts[1]);
                else if (twoParts[0].Contains("Subnet Mask"))
                    results.Add(twoParts[1]);
            }
        }
        string data = "";
        foreach (var d in results)
        {
            data += d + "\n";
        }
        MessageBox.Show(data);
    
Arslan Ali
  • 450
  • 4
  • 12