This tool allows you to intercept connections made from a java application
You can run the agent using
java -javaagent:ConnectionInterceptor-1.0-SNAPSHOT.jar -jar application.jar
to disable connections you can use:
java -javaagent:ConnectionInterceptor-1.0-SNAPSHOT.jar=disable -jar application.jar
and yes this can be dynamically attached from another application.