Sign in to follow this  
Sir Sapo

Retrieving Your IP Address

Recommended Posts

I was trying to figure out why my friend couldn't connect to my game's server on my computer so I looked it up in the forum FAQ, and found this
Quote:
Q18) How do I get the IP address of the machine I'm running on? Typically, it's a bad idea to get your own IP address, because it's not certain that the address is visible to people outside your router. Also, many machines have more than one IP address (each interface has one in a machine). Last, not all ISPs or routers have DNS/reverse DNS set up such that gethostname() followed by gethostbyname() will give you the right answer. To use command-line tools to list your addresses on Windows, use "ipconfig". On Linux, use "ifconfig". On BSD, use "ifconfig" but you probably have to be root. To programmatically determine the CORRECT address to use, you have to bounce a query off a server that's available on the public internet, and look at what address it returns back. This will work correctly for situations where you're behind NAT (routers/firewalls). If you want to know the list of all interface addresses, say for selectively binding to only some interface, then you need to use OS-specific system calls; i e you need to do whatever ipconfig/ifconfig does, which involves the network device API on Windows, and walking /proc on Linux.
What I got from that is that I need to send a request for my IP to some server somewhere and record its response. Can anyone tell me how to do this, or show me a tutorial on the subject. Thanks.

Share this post


Link to post
Share on other sites
If you're being a gateway, and only have an internal IP address assigned to your computer.. and want to know what IP address your traffic is sent out from (and expects to receive responses to)

www.whatismyip.com

Unless you really want to get the code itself to do this.. then I completely misinterpreted the required end result and I'll go back to watching t.v.

The biggest issue that I see with trying to code in a method to retrieve your publically visible IP address is that your NAT daemon will molest the packets to remove that IP address.. and bungling with the daemon's code could introduce compatibility problems with other active interfaces.

Share this post


Link to post
Share on other sites
So then how can I allow my friend to join my server? How do other games like Quake and Unreal do this? My game works over a LAN, but I would really like to b able to run it ovewr the internet.

Share this post


Link to post
Share on other sites
Most likely you'll need to set up a port mapping in your gateway, so that all traffic of a certain protocol (TCP, UDP, probably not ICMP heh) on a particular port or range of ports will be redirected to the internal IP address that the server is hosted upon.

In the documentation for the game, it should have a section on what ports need to be mapped. Otherwise, you can find that information about it online at the games website.

Share this post


Link to post
Share on other sites
Quote:
Original post by sordid
Most likely you'll need to set up a port mapping in your gateway, so that all traffic of a certain protocol (TCP, UDP, probably not ICMP heh) on a particular port or range of ports will be redirected to the internal IP address that the server is hosted upon.

In the documentation for the game, it should have a section on what ports need to be mapped. Otherwise, you can find that information about it online at the games website.



Sorry If I was unclear, when I said my game I meant the game I was trying to develop, therefore, no documentation that I dont already know(which is unfortunately, alot).

Share this post


Link to post
Share on other sites
I thought maybe you wanted to alter your gateway's NAT daemon itself to keep particular packets (possibly the ICMP Echo/Reply packets) unmolested.

At any rate.. what game are we talking about here? Most games usually have one udp port that needs to be remapped. DirectPlay-based games sometimes or usually require both -- I'm not entirely sure.. I code winsock only.

Share this post


Link to post
Share on other sites
The game I am making is a 2D action game. I am writing it in C++ and using winsock for the networking with TCP as the protocol. I know that nothing is wrong with my client/server code, because it works in a LAN. My problem arose when I was trying to play the game with my friend. When I had him put in the IP address that the www.whatismyip.com site gave me, he still couldn't connect to the server I had created.

Share this post


Link to post
Share on other sites
Here's a few scenarios:

Your server computer is connected directly to the internet and is not firewalled: It should work.


Your server computer is connected to the internet and is firewalled: You will need to open the port your server runs off of.


Your server computer is connected to a gateway computer or a router which is connected to the internet: You will need to, on your gateway or router, map the port your server runs off of so that it redirects the traffic to the computer that you're running the server on. Either way, you'll have to consult the documentation/manual on your specific gateway/router on how to remap ports. You could tell us what it is, however.. somebody should be able to recap the process from memory.

Share this post


Link to post
Share on other sites
The computer I was running the Server on is connected to a router wirelessly, and the firewall was turned off. So if I connect the server computer directly to the internet, bypassing the router, and then start my server, could my friend connect, even though he is behind a router?

Share this post


Link to post
Share on other sites
clients should be able to connect to the server even if the client is behind a firewall & gateway/router (provided that the client makes the first communication on any specific port to the server, and not vice versa)

however, if you absolutely cannot do a port mapping on the router, then you will have to connect the server computer directly to the internet.


Share this post


Link to post
Share on other sites
You can simulate a LAN over the internet using Hamachi http://www.hamachi.cc

If you want to get past the firewall you can set your computer as the DMZ host, revealing it to the internet. You can get your LAN ip by going to Start - Run - Then typing CMD

A DOS prompt should show up, type in ipconfig and it will give you your lan IP. Which usually looks like this: 192.168.1.101 But it varies depending on your router.

To get your WAN ip go to: www.whatismyip.com and then just host using Internet TCP/IP.

Share this post


Link to post
Share on other sites
If he was able to modify the gateway settings to set up the computer as a DMZ, it would still be far safer to just portmap. This way, he gets the same functionality barring an unforseen completely whacked out network protocol, and he's still behind an effective NAT. On average, what is it.. 14 seconds it takes for a unsecure Windows based machine to potentially become compromised?

The LAN software would be an ugly requirement for the game if behind a firewall.

The rest was covered already.

Let this topic die! [wink] heh

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this