If you do not mind running under SecurityManager , and the list of IP addresses is static, you can do this through the security.policy file. Just highlight SocketPermission "accept" only for the IP addresses with which you want to accept connections. However, doing this in code or a firewall, as suggested in other answers, is probably preferable.
source share