0

I need client remote port for some validation. I tried to get Remote Port in request but result come only Zero 0. I seen that OOTB class DynamoHttpServletRequest its default return the zero any way to get the client remote port.

In OOTB class DynamoHttpServletRequest returns

public int getRemotePort() {
    return 0;
}

Is there any possibility to get remote port? Any alternative ways to get Client Remote port?

Justin
  • 15
  • 5
  • DynamoHttpServletRequest provides access to server's implementation of HttpServletRequest (by getRequest() method). Have you tried accessing remote port directly from there? – pantuptus Oct 30 '20 at 14:53
  • thank you now i got the remote port of the client. After try this DynamoHttpServletRequest.getRequest().getRemotePort() i got it. – Justin Nov 02 '20 at 04:58
  • @pantuptus i have small clarification is there any possibility to get a constant remote port for the client. its look like session if user enter into the site the browser created a client port that port only destroy when user closed the connection until i need same port for hole request (not every request response time port change). is there any possibilities ? – Justin Nov 02 '20 at 07:49
  • I don't get your question. Are you developing on client side or server side? If server side, then its not your job to influence the port that the client is requesting you. – pantuptus Nov 03 '20 at 12:56
  • @pantuptus i am try to do some validation token for security purpose to avoid the bots create a request. Am create a token with client port and set in the session after some request only i get the client port and session set client port also same mean valid request check. – Justin Nov 04 '20 at 05:41
  • Still not clear. You expect that client is requesting your app always with the same port during a particular session. But on the other hand, you observe that it is not a rule. So why do you still want to validate that? – pantuptus Nov 04 '20 at 12:52
  • Because of if user enter into the app that time i fetch the remote port form request and set in session. Form submission time i fetch the remote port to validate stored session remote port and current request remote port is same mean i am allow to submit the form. main reason some of the form are submitted by bots without valid data. i tried re-captcha validation that also some time failed. So I validate the user-agent and remote port with re-captcha it will help to avoid from bots. that's only i need client remote port but each and every request port number is change so any alternative ways – Justin Nov 05 '20 at 05:30
  • Then I don't think you should validate against remotePort. See my comment to the other question you asked: https://stackoverflow.com/questions/64641731/how-to-get-a-user-clinet-remote-port-in-java-dynamohttpservletrequest. – pantuptus Nov 05 '20 at 16:04

1 Answers1

0

I got the remote port help of implemented class HttpServletRequest.

public int getClientPort(DynamoHttpServletRequest req){ 
    int remortPortVal = req.getRequest().getRemotePort();
    return remortPortVal;
}
Justin
  • 15
  • 5