IP Adresi Tespiti
IP tespiti için kesin çözüm
Klasik olarak aşağıdaki kod ile IP adresinin tespit edileceği söylenir:
string ip = Request.UserHostAddress;
Ama bu kod zaman zaman tam olarak bize sonucu döndürmüyor.
Fazla detaya gerek yok, aşağıdaki metot ile tam ve kesin olarak IP tespiti yapabilirsiniz:
public string IP()
{
string ip = ""
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
string[] ipRange = ip.Split(",".ToCharArray());
ip = ipRange[0];
}
}
if (string.IsNullOrEmpty(ip))
if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != null)
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
ip = ip.Trim();
return ip;
}
İşte bu kesin olarak size IP adresini verecektir.
Herkese iyi çalışmalar.
#ip #UserHostAddress