//取得Lan ip ex:192.168.0.2

 private string GetLanIP()
    {
        string strHostName = System.Net.Dns.GetHostName();

        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

        foreach (IPAddress ipAddress in ipEntry.AddressList)
        {
            if (ipAddress.AddressFamily.ToString() == "InterNetwork")
            {
                return ipAddress.ToString();
            }
        }

        return "-";
    }

// 取得 public ip ex:168.95.1.1  在本機上試的話 會得到 ::1 

 private string GetIP()

{

        string ip = String.Empty;

         if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null)
        {
            ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString()

         }
        else
        {
            ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString();

         }

            return ip;

}

 
 
arrow
arrow
    全站熱搜

    mmfily 發表在 痞客邦 留言(0) 人氣()