How can I establish a ServerSocket that doesn't accept connections from certain IPs, especially before accept() returns a Socket instance?

Tim Rohaly

This is probably better done externally to your application, using packet filtering software or hardware.

You also have the option of providing your own socket implementation factory and installing it by invoking ServerSocket.setSocketFactory(). You could then code your factory to provide sockets which accept/deny based on source IP.