Is there a way to block incoming connections to a java server if the client has a certain ip address?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Accept the connection, then get the
Socketfor that connection. After that, it’s a simple as callingsocket.getInetAddress()and deciding if you want to reply with data or close the socket.Beware, due to the prevalance of NAT, you might not be able to really differentiate who is connecting to you, as the request may have been rewritten (by NAT) to appear to come from a gateway machine instead of an end-client.
If this is an attempt to provide a “slightly more secure” set of connections, remember that IP addresses are trivially spoofed, and there are no real barriers from someone else setting their machine to have your IP address.