Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Getting an IP address  (Read 29225 times)

0 Members and 2 Guests are viewing this topic.

borfast

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • http://www.borfast.com
Getting an IP address
« on: April 12, 2008, 03:53:46 am »
Hello.

I was looking at the network tutorial and I read something I think is incorrect:

Quote
Please note that GetPublicAddress() is very slow : the only way to get a public address is to get it from the outside (especially when you are behind a proxy or a firewall), so it connects to an external website (www.whatismyip.org) and parse the returned web page to extract the public IP address. So, don't use it too much.


Please, don't get me wrong, I'm not trying to bash you or diminish the value of your work with SFML but I don't think this is the case at all. You are going through a lot of unnecessary work when you could just grab the IP address from the public interface.

In the case the computer is behind a proxy/firewall (a very common setup, nowadays, with the advent of broadband home routers/gateways), then you would need something like what you have implemented but otherwise, grabbing the IP address of the public interface is all that is necessary - there's no need to go to a public website to get it.

I've glanced at the network code and from what I can tell, even for the local address you are jumping through loops when all you need is to get an address from an interface.

Is there a reason why you did it this way?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting an IP address
« Reply #1 on: April 12, 2008, 06:27:50 am »
Can you explain "grab the IP address from the public interface" ? How would you do that ?

Quote
In the case the computer is behind a proxy/firewall (a very common setup, nowadays, with the advent of broadband home routers/gateways), then you would need something like what you have implemented but otherwise, grabbing the IP address of the public interface is all that is necessary

How would you know whether the computer is behind a proxy/firewall or not ?

Quote
I've glanced at the network code and from what I can tell, even for the local address you are jumping through loops when all you need is to get an address from an interface.

For local address, I'm just getting from the socket. Again, can you explain what you suggest ?
Laurent Gomila - SFML developer

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Getting an IP address
« Reply #2 on: April 12, 2008, 06:49:33 am »
You should search on google before posting such thing.. i dont know any way to get WAN ip. You can do ipconfig /all to get an ip on window but u can't get WAN ip if your behind a router because it will return your LAN ip. Google WAN and LAN if you don't know the difference.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

borfast

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • http://www.borfast.com
Getting an IP address
« Reply #3 on: April 17, 2008, 12:34:10 pm »
Laurent, I meant that you could get the IP from the network interface, like you do in IPAddress::GetLocalAddress(), instead of loading a webpage and parsing the HTML.

You would know if the computer is behind a router or firewall if the address you get is in the range of local addresses:
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
169.254.0.0 - 169.254.255.255

Only then would you resort to the webpage method. And even so, although I don't have an alternative to give you right now, my experience tells me it is a very bad idea to rely on a website (especially being just one website) to get this information. But I don't think anyone would dispute that.

As for the local address, you're right, I'm sorry, I don't know why but it looked like you were also doing stuff that seemed unnecessary to me. Forget about that, then.



Daazku, perhaps you should google "how to behave on a forum" before posting such a thing.
Or you could just look into the possibility that when someone says something which doesn't agree with what you think, it can actually make sense, and listen to what that person has to say before calling him/her stupid in an indirect way. But that's just me talking...

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Getting an IP address
« Reply #4 on: April 17, 2008, 03:17:40 pm »
borfast, you are right in that if the address is in a private range then they will be behind a firewall or router and will have a different public address. However, AFAIK, it is possible to set up a NAT for public addresses as well. If so, then you can't assume that just because the IP isn't in the private ranges that it will be the machines public address. As such, the only reliable way to get the public address is to use a lookup tool such as whatismyip.com.

If Laurent had the resources to spare though, he could set up a server that accepts input on a single port and the only response ever given is the originating IP address of the request. It would probably be faster than parsing whatismyip.com but would require the resources to have a permanent server up and be sure that it would always be available even if SFML is discontinued in the future.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting an IP address
« Reply #5 on: April 17, 2008, 03:31:30 pm »
Yes, as you say I can't have my own server, so whatismyip.org is the most reliable one I've found.

Don't worry about parsing, the page only contains the IP address ;)
Laurent Gomila - SFML developer

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Getting an IP address
« Reply #6 on: April 17, 2008, 05:06:12 pm »
Parsing time is negligible compared to the potential time to get a response from whatismyip.com, eh? ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting an IP address
« Reply #7 on: April 18, 2008, 03:18:00 am »
Exactly :)
Laurent Gomila - SFML developer