locked
How to get the domain name for a client machine? RRS feed

  • Question

  • I have to check if two different machines belong to the same domain. I have the machine names with me lets say mac1 and mac2 (or might be their IP addresses). These machines are in network but might have different domains. My code should tell me if they belong to same domain or not. How could i check that in an asp.net application?

    Thursday, October 10, 2013 3:44 PM

Answers

  • After tickling around, I found the answer. Actually Directory.Exists when called in a web app runs on IIS. IIS has some restriction due to which it does not have access on the network of the server computer on which the Web App is running.

    I also had a service running on that server machine. I put the above code in the that service and called the function through a remote call. Since the service has access on the network, it was able to check for the existence of the machine and hence returned true if the machine was in the same domain as the server.

    • Marked as answer by vmohit Thursday, October 17, 2013 1:42 PM
    Thursday, October 17, 2013 1:42 PM

All replies

  • Try this and let me know

    IPAddress ip = IPAddress.Parse("pass client ip);
    IPHostEntry gethost = Dns.GetHostByAddress(ip);
    Response.Write(gethost.HostName);
    Another option http://sujitkumar.wordpress.com/2008/08/14/32/


    A.m.a.L Hashim
    Microsoft Most Valuable Professional
    My Blog - Dot Net Goodies


    Thursday, October 10, 2013 4:37 PM
  • After tickling around, I found the answer. Actually Directory.Exists when called in a web app runs on IIS. IIS has some restriction due to which it does not have access on the network of the server computer on which the Web App is running.

    I also had a service running on that server machine. I put the above code in the that service and called the function through a remote call. Since the service has access on the network, it was able to check for the existence of the machine and hence returned true if the machine was in the same domain as the server.

    • Marked as answer by vmohit Thursday, October 17, 2013 1:42 PM
    Thursday, October 17, 2013 1:42 PM