Getting the IP address of server in ASP.NET?

前端 未结 6 1975
感情败类
感情败类 2020-11-30 03:53

How do I get the IP address of the server that calls my ASP.NET page? I have seen stuff about a Response object, but am very new at c#. Thanks a ton.

6条回答
  •  遥遥无期
    2020-11-30 04:13

      //this gets the ip address of the server pc
      public string GetIPAddress()
      {
         string strHostName = System.Net.Dns.GetHostName();
         //IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); <-- Obsolete
         IPHostEntry ipHostInfo = Dns.GetHostEntry(strHostName);
         IPAddress ipAddress = ipHostInfo.AddressList[0];
    
         return ipAddress.ToString();
      }
    

提交回复
热议问题