Close port on exit (UPnP)

This commit is contained in:
MaxXor 2014-07-30 16:34:42 +02:00
parent 34e0cfd9b5
commit cc825fabb2
2 changed files with 20 additions and 4 deletions

View File

@ -34,12 +34,25 @@ public static void ForwardPort(ushort port)
try
{
UPnPNAT upnpNat = new UPnPNAT();
IStaticPortMappingCollection portMap = upnpNat.StaticPortMappingCollection;
portMap.Add(port, "TCP", port, ipAddr, true, "xRAT 2.0.0.0 UPnP");
IStaticPortMappingCollection portMap = new UPnPNAT().StaticPortMappingCollection;
if (portMap != null)
portMap.Add(port, "TCP", port, ipAddr, true, "xRAT 2.0 UPnP");
}
catch { return; }
catch
{ }
}).Start();
}
public static void RemovePort(ushort port)
{
try
{
IStaticPortMappingCollection portMap = new UPnPNAT().StaticPortMappingCollection;
if (portMap != null)
portMap.Remove(port, "TCP");
}
catch
{ }
}
}
}

View File

@ -125,6 +125,9 @@ private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
if (listenServer.Listening)
listenServer.Disconnect();
if (XMLSettings.UseUPnP)
UPnP.RemovePort(ushort.Parse(XMLSettings.ListenPort.ToString()));
nIcon.Visible = false;
}