我使用来自Port Forwarding by Using "HNetCfg.NATUPnP" Ole Object Failed的代码进行端口转发,工作正常,只是在应用程序终止时不能关闭端口。
AddUPnPEntry(1234, 'Hello3', '192.168.1.34');1234端口仍然是开放的,尽管我重新启动了我的pc,我在canyouseeme.org上测试了它。那我怎么才能关闭港口?
编辑:解决,我只需要重新启动(关闭和打开)我的路由器,以关闭端口再次。
发布于 2014-02-21 16:13:58
AddUPnPEntry()使用IStaticPortMappingCollection.Add()方法。有一个相关的IStaticPortMappingCollection.Remove()方法,例如:
Procedure RemoveUPnPEntry(Port: Integer);
Var
Nat: Variant;
Ports: Variant;
Begin
try
Nat := CreateOleObject('HNetCfg.NATUPnP');
Ports := Nat.StaticPortMappingCollection;
Ports.Remove(Port, 'TCP');
except
ShowMessage('An Error occured with removing UPnP Ports. ' +
'Please check to see if your router supports UPnP and ' +
'has it enabled or disable UPnP.');
end;
End;
RemoveUPnPEntry(1234);https://stackoverflow.com/questions/21929833
复制相似问题