.NET [C#.NET] 클라이언트 컴퓨터 IP 찾기 / 특정 아이피에서만 보기
페이지 정보
본문
string strUserHostAddress = HttpContext.Current.Request.UserHostAddress;
string strREMOTE_ADDR = Context.Request.ServerVariables["REMOTE_ADDR"];
string strUserHostName = Request.UserHostName;
string strUserIP = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] == null)
strUserIP = HttpContext.Current.Request.UserHostAddress;
else
strUserIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
#region IPv4
string strUserIPv4 = string.Empty;
foreach (IPAddress _IP in Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress))
{
if (_IP.AddressFamily.ToString() == "InterNetwork")
{
strUserIPv4 = _IP.ToString();
break;
}
}
if (strUserIPv4 == string.Empty)
{
foreach (IPAddress _IP in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (_IP.AddressFamily.ToString() == "InterNetwork")
{
strUserIPv4 = _IP.ToString();
break;
}
}
}
#endregion
//화면에 정보를 출력
writer.Write("UserHostAddress : " + strUserHostAddress + "<br />");
writer.Write("Remote Address : " + strREMOTE_ADDR + "<br />");
writer.Write("UserHostName : " + strUserHostName + "<br />");
writer.Write("UserIP : " + strUserIP + "<br />");
writer.Write("UserIPv4 : " + strUserIPv4 + "<br />");
자료출처
댓글목록
등록된 댓글이 없습니다.