Author Topic: Hosting server not using correct IP Address.  (Read 11438 times)

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Hosting server not using correct IP Address.
« on: November 22, 2015, 12:31:20 PM »
For some reason hosting a TNet server will start up correctly but when trying to connect to the server the IP address it is using is incorrect.
As you can see from this screen shot its saying "External IP: 0.0.1.19" This isnt my IP address. My IP address is 66.177.xx.xxx. If I give the same exe to my friend to host.
It will show the correct static IP address. The only weird thing about this is that when someone direct connects to my static IP addresss "66.177.xx.xxx:5127" they can connect correctly.
PS: yes ive port forwarded. no its not my firewall.



cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Hosting server not using correct IP Address.
« Reply #1 on: November 23, 2015, 08:00:43 PM »
Can you go to http://icanhazip.com and tell us the output? Additionally, can you detail your LAN setup? What model is your router? Are you behind a switch / hub, or an additional router? What OS are you building on?

The relevant code:
externalAddress getter: line 253 of TNTools.cs
function GetExternalAddress: line 321 of TNTools.cs (also, check to make sure you aren't setting ipCheckerUrl. Let it use the defaults.)

Might also be a problem with the webclient and parsing:
function ResolveExternalIP: line 344
function ResolveAddress: line 391 (parses what the above function received)

I have a feeling most - if not all - of your issues are caused by something in your LAN setup. Set up some breakpoints on those lines and check if the variables are matching up. Note the first one that doesn't seem right.

edit: oh, I have the same issue :P it's because your external IP is ipv6, I assume. The parsing doesn't account for ipv6 addresses (though TNet should support ipv6). I'll write up a fix after dinner and edit this again. In the meantime, you could try forcing an ipv4 address. On windows: Open Network & Sharing Center -> Change adapter settings -> right click your physical NIC and select Properties -> uncheck the Internet Protocol Version 6 box and click OK -> right click your physical NIC again and select Disable, then Enable.

edit2: In TNTools.cs, in the static bool ResolveExternalIP (string url) function, replace the following:
  1. string[] split1 = text.Split(':');
  2.  
  3. if (split1.Length >= 2)
  4. {
  5.     string[] split2 = split1[1].Trim().Split('<');
  6.     mExternalAddress = ResolveAddress(split2[0]);
  7. }
  8. else mExternalAddress = ResolveAddress(text);
  9.  
With:
  1. mExternalAddress = ResolveAddress(text);
  2.  

I'm not sure what adverse effects this could have with the parsing. I can't think of any IP related string with "<" in it. I checked the webpages and it's just plaintext, too. So no html tags. Hopefully Aren will see this and include it in the next TNet update.
« Last Edit: November 23, 2015, 08:59:55 PM by cmifwdll »

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Hosting server not using correct IP Address.
« Reply #2 on: November 24, 2015, 11:14:28 AM »
Thanks for the reply ill try these.

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Hosting server not using correct IP Address.
« Reply #3 on: November 24, 2015, 11:56:53 AM »
http://icanhazip.com/ is returning "2601:346:400:e3f0:94fe:9bdf:c8:209a"

My router is a Technicolor TC8305C. It was giving by Comcast. No im not on a switch / hub nor an additional router. Im building on Windows 7.



I did the edit on the server but it now says


edit:
I seems that icanhazip returns my ipv6 but the other two resolvers actually return the correct one, I changed GetExternalAddress () (line 329)
  1. if (ResolveExternalIP(ipCheckerUrl)) return mExternalAddress;
  2. if (ResolveExternalIP("http://icanhazip.com")) return mExternalAddress;
  3. if (ResolveExternalIP("http://bot.whatismyipaddress.com")) return mExternalAddress;
  4. if (ResolveExternalIP("http://ipinfo.io/ip")) return mExternalAddress;
  5.  
to this order
  1. if (ResolveExternalIP(ipCheckerUrl)) return mExternalAddress;
  2. if (ResolveExternalIP("http://bot.whatismyipaddress.com")) return mExternalAddress;
  3. if (ResolveExternalIP("http://icanhazip.com")) return mExternalAddress;
  4. if (ResolveExternalIP("http://ipinfo.io/ip")) return mExternalAddress;
  5.  

It seems the bot.whatismyipaddress returns my actual usable IP Address. This is a temporary fix i suppose. im not sure what effects this could have on other server hosters though.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Hosting server not using correct IP Address.
« Reply #4 on: November 24, 2015, 11:58:55 PM »
Your fix assumes bot.whatismyipaddress.com will always return ipv4 over ipv6. Additionally, assumes your ISP will always assign you both an ipv4 and ipv6 address (won't be the case for long).

If you go with the solution I posted you won't have any issues with that. You could even combine the solutions if you'd like.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hosting server not using correct IP Address.
« Reply #5 on: November 25, 2015, 06:32:13 PM »
That's strange... I also can't think of why the '<' would be there. I wonder why I added it! I'll change it to just use ResolveAddress, thanks cmifwdll!

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Hosting server not using correct IP Address.
« Reply #6 on: November 26, 2015, 12:56:20 PM »
That's strange... I also can't think of why the '<' would be there. I wonder why I added it! I'll change it to just use ResolveAddress, thanks cmifwdll!
Can you go to http://icanhazip.com and tell us the output? Additionally, can you detail your LAN setup? What model is your router? Are you behind a switch / hub, or an additional router? What OS are you building on?

The relevant code:
externalAddress getter: line 253 of TNTools.cs
function GetExternalAddress: line 321 of TNTools.cs (also, check to make sure you aren't setting ipCheckerUrl. Let it use the defaults.)

Might also be a problem with the webclient and parsing:
function ResolveExternalIP: line 344
function ResolveAddress: line 391 (parses what the above function received)

I have a feeling most - if not all - of your issues are caused by something in your LAN setup. Set up some breakpoints on those lines and check if the variables are matching up. Note the first one that doesn't seem right.

edit: oh, I have the same issue :P it's because your external IP is ipv6, I assume. The parsing doesn't account for ipv6 addresses (though TNet should support ipv6). I'll write up a fix after dinner and edit this again. In the meantime, you could try forcing an ipv4 address. On windows: Open Network & Sharing Center -> Change adapter settings -> right click your physical NIC and select Properties -> uncheck the Internet Protocol Version 6 box and click OK -> right click your physical NIC again and select Disable, then Enable.

edit2: In TNTools.cs, in the static bool ResolveExternalIP (string url) function, replace the following:
  1. string[] split1 = text.Split(':');
  2.  
  3. if (split1.Length >= 2)
  4. {
  5.     string[] split2 = split1[1].Trim().Split('<');
  6.     mExternalAddress = ResolveAddress(split2[0]);
  7. }
  8. else mExternalAddress = ResolveAddress(text);
  9.  
With:
  1. mExternalAddress = ResolveAddress(text);
  2.  

I'm not sure what adverse effects this could have with the parsing. I can't think of any IP related string with "<" in it. I checked the webpages and it's just plaintext, too. So no html tags. Hopefully Aren will see this and include it in the next TNet update.


Thanks for all of the help both of you.