I do use the detection on an external website, and if it was not reachable that would be fine. I am more concerned with the ports being opened on 127.0.0.1. I made a small script copying what you do in the TNTools.cs to obtain the local ip and verify it. I let this run for 4 hours and not once did i get 127.0.0.1 as the local (lan) ip. I then tried to start a server and the first time it used 127.0.0.1 as the ip to open the ports on. I am trying to avoid modifying your code as when we get an update it gets wiped out. I thought about inheriting the TNet.UPnP but there are protected members that are not accessible (one being the local ip). I was going to do that so i could check the ip and if it was the 127.0.0.1 the check again to make sure i get the correct local ip.
I had put a fix in version 1.7.x on mine in the past but have updated since then. What I did was get the local ip and put that into a variable and then checked it, if it was 127.0.0.1 i would then get and check again.
I believe this is what I had added. (* in front of now or edited lines)
void Open (int port, bool tcp, OnPortRequest callback)
{
int id = (port << 8) | (tcp ? 1 : 0);
if (port > 0 && !mPorts.Contains(id) && mStatus != Status.Failure)
{
mPorts.Add(id);
* IPAddress tempLocal = Tools.localAddress;
* for (int i = 0; i < 10; i++)
* {
* if (tempLocal.ToString() != "127.0.0.1")
* {
* return;
* }
* else
* {
* tempLocal = Tools.localAddress;
* }
* }
ExtraParams xp
= new ExtraParams
(); xp.callback = callback;
xp.port = port;
xp.protocol = tcp ? ProtocolType.Tcp : ProtocolType.Udp;
xp.action = "AddPortMapping";
xp.request = "<NewRemoteHost></NewRemoteHost>\n" +
"<NewExternalPort>" + port + "</NewExternalPort>\n" +
"<NewProtocol>" + (tcp ? "TCP" : "UDP") + "</NewProtocol>\n" +
"<NewInternalPort>" + port + "</NewInternalPort>\n" +
* "<NewInternalClient>" + tempLocal + "</NewInternalClient>\n" +
"<NewEnabled>1</NewEnabled>\n" +
"<NewPortMappingDescription>" + name + "</NewPortMappingDescription>\n" +
"<NewLeaseDuration>0</NewLeaseDuration>\n";
xp
.th = new Thread
(OpenRequest
); lock (mThreads) mThreads.Add(xp.th);
xp.th.Start(xp);
}
else if (callback != null)
{
callback(this, port, tcp ? ProtocolType.Tcp : ProtocolType.Udp, false);
}
}
I am at work right now so I can not verify, but if you would like I can try this when I get home and make sure that 127.0.0.1 is no longer being used.