Programming > JSP/HTML/JSTL

브라우저에서 원격 IP 확인하기 (접근IP)

클라이언트 접속 IP 확인용 소스

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%!
String getClientIP(HttpServletRequest request) {
  String ip = request.getHeader("X-FORWARDED-FOR"); 
  if (ip == null || ip.length() == 0) {
    ip= request.getHeader("Proxy-Client-IP");
  }
  if (ip == null || ip.length() == 0) {
    ip= request.getHeader("WL-Proxy-Client-IP");  
  }
  if (ip == null || ip.length() == 0) {
    ip= request.getRemoteAddr() ;
  }
  return ip;
}
%>
<html>
<head>
<title>Remote IP</title>
</head>
<body>

<hr>
<p> Your IP Adress : <b style="color:red;font-size:4em;"><%=getClientIP(request)%></b> </p>
<hr>

</body>