cancel
Showing results for 
Search instead for 
Did you mean: 

Get client IP address

Former Member
0 Kudos

Hi ,

I need to get IP address of the client(user) not server. I tried with these codes, both these returned IP address of the server but not client. Is there any other way? Please help.

1) try{

InetAddress thisIp =InetAddress.getLocalHost();

String IPAddress = thisIp.getHostAddress();

wdContext.currentContextElement().setIp(IPAddress);

}catch(Exception ee){

}

2)

IWDRequest request = WDProtocolAdapter.getProtocolAdapter() .getRequestObject() ;

String ip= request.getClientHostAddress();

Thanks,

Jai

Accepted Solutions (0)

Answers (2)

Answers (2)

dao_ha
Active Contributor
0 Kudos

Hi Jai,

Your #1 method won't work because it gets the localHost which is the app server.

Your #2 method should work, try this

String ip = WDProtocolAdapter.getProtocolAdapter().getRequestObject().getClientHostAddress();

and debug to see what value gets there.

Hope it helps,

Dao

Qualiture
Active Contributor
0 Kudos

Hi,

Use

String clientHost = TaskBinder.getCurrentTask().getWebContextAdapter().getHttpServletRequest().getRemoteHost();

Best regards,

Robin