public static boolean closePort(int port) {
try {
InternetGatewayDevice[] IGDs = InternetGatewayDevice.getDevices(discoveryTimeout);
if (IGDs != null) {
// let's the the first device found
InternetGatewayDevice testIGD = IGDs[0];
System.out.println("Found device " + testIGD.getIGDRootDevice().getModelName());
// now let's open the port
String localHostIP = InetAddress.getLocalHost().getHostAddress();
// we assume that localHostIP is something else than 127.0.0.1
boolean unmapped = testIGD.deletePortMapping(null, port, "TCP");
if (unmapped) {
System.out.println("Port " + port + " unmapped");
}
return unmapped;