1
텍스트 상자에 현재 뷰어 IP 주소를 가져와 표시하는 방법은 무엇입니까?IP 주소 받기
텍스트 상자에 현재 뷰어 IP 주소를 가져와 표시하는 방법은 무엇입니까?IP 주소 받기
당신은 HttpRequest.UserHostAddress 재산, 또는 HttpRequest.ServerVariables 수집의 REMOTE_ADDR 키를 사용할 수 있습니다, 그들은 모두 string
, 그리고 당신은 단지 당신의 텍스트 상자에 값을 할당 할 수 있습니다
HttpContext.Current.Request.UserHostAddress;
또는
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
/// <summary>
/// IP Adress of computer
/// </summary>
/// <returns>return a string value(Ip address)</returns>
public static string IPaddress()
{
String strHostName = "";
strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ipEntry.AddressList;
string IPaddress = "";
for (int i = 0; i < addr.Length; i++)
{
IPaddress = addr[i].ToString().Trim();
}
return IPaddress;
}
물론 이것은 요청이 보낸 IP 주소 만 가져옵니다. 프록시 (덕분에 프록시, NAT 등)가 실제로 속한 것이 아닙니다. 방문자의 컴퓨터 (그러나 신뢰할 수있는 방법으로 그 정보를 수집 할 수는 없습니다). – Quentin