?1
public
?
static
?String?getIp(HttpServletRequest?req)?
{
?2
????????String?ip_for?
=
?req.getHeader(
"
x-forwarded-for
"
);
?3
????????String?ip_client?
=
?req.getHeader(
"
http_client_ip
"
);
?4
????????String?un?
=
?
"
unknown
"
;
?5
?6
????????
if
?(ip_for?
!=
?
null
?
&&
?
!
ip_for.equalsIgnoreCase(un)
?7
????????????????
&&
?ip_for.trim().length()?
>
?
0
)?
{
?8
????????????
return
?ip_for;
?9
????????}
?
else
?
if
?(ip_client?
!=
?
null
?
&&
?
!
ip_client.equalsIgnoreCase(un)
10
????????????????
&&
?ip_client.trim().length()?
>
?
0
)?
{
11
????????????
return
?ip_client;
12
????????}
?
else
?
{
13
????????????
return
?req.getRemoteAddr();
14
????????}
15
????}



?2

?3

?4

?5

?6

?7



?8

?9

10



11

12



13

14

15
