Find internet IP-Address (WAN)? [C#/CS 2005]

Shaitan00

Well-known member
Joined
Aug 11, 2003
Messages
343
Location
Hell
Okay - I was expecting to find a lot of documentation on this problem but oddly enough I seem to be coming up pretty blank...

I am creating a SERVER / CLIENT network game - in this game the client will send a UDP "HELLO|XXX.XXX.XXX.XXX" message to the SERVER - the server will respond to the client with a "HEY|XXX.XXX.XXX.XXX". Then both client and server will form TCP connections using these IP-Addresses.
Now this works fine in my LAN (of course) but when I try to play online it doesnt work for one obvious reason, the IP-Address sent back-and-forth is the LAN IP and since I have a router it is not my REAL internet ip-address...
I use the following code to determine my CLIENT & SERVER ip-addresses...
Code:
IPAddress ipServer = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
This code returns stuff like "192.168.0.1", "192.168.0.2", etc.. (which is perfect for my LAN gaming)....

Is there maybe a way to get the IP-Address from the incoming UDP packet instead of explicitly sending it?
I use the following code to receive, I think in java (way-back-when) there was a way to get the ip-address of the person who sent the data from the socket? (could be wrong)
Code:
int nReceived = sktServer.ReceiveFrom(buffer, ref epSender);

Or a way to maybe loop to my router somehow to get my actual WAN (internet) ip-address?
How do people usually solve this problem? I assume it is encountered fairly often in the real world....

Any ideas, hints, and help would be greatly appreciated, thanks
 
Difficult to do under setups where you are behind a router/gateway. I finally "cheated" by making a PHP webpage that simply returns the IP address of the vistor to the page. This seemed to be the only realistic way to do it.

Hopefully in the future router/gateways will have a common WAN IP return call that can be made. Kind of doubt that though.
 

Similar threads

P
Replies
0
Views
176
Policy standard local admin account with Active Di
P
Back
Top