string strHostName = System.Net.Dns.GetHostName(); //clientIPAddress是一個數組,可能有多個數據 var clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName); string clientip = clientIPAddress.GetValue(0).ToString();
示例代碼git
Find Client IP Address And Location in ASP.NETgithub