Archived

This topic is now archived and is closed to further replies.

DPlay: Finding the External IP Address of Local Machine

This topic is 5088 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just so everyone knows, I did do a search on this forum before posting this question, and all the results that came up were either 1) people misinterpreting the question or 2) cop-outs that fall back on windows sockets and don''t necessarily find the external IP address (if you''re on a router with NAT). So.... I''m running a game server. I need to find out it''s external IP address (this is from the local machine) so that I can tell other people what it is, so that they can connect to my DPlay session over the internet. Note, I want the external IP address - the one that the internet sees. Is there any way at all to retrieve this without resorting to windows sockets? I can''t believe that the designers of DPlay would leave this functionality out! My game server is written in C#, so if there is anything like a System.Environment property that I could check to get this, that would be good too. I know how to do this with winsock (if not from C#). My interest in finding a DPlay solution is derived from my monkey-like curiousity. Thanks for any help! ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Coding: http://www.stanford.edu/~jjshed/coding Miscellany: http://www.stanford.edu/~jjshed

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
2 minutes on msdn.. sheesh..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/play/advancedtopics/nats/usingnatresolver.asp

Share this post


Link to post
Share on other sites
> I need to find out it''s external IP address

There is no way the OS can tell you this because the only thing it sees is the first router up the link. To get the global IP, you need to ''bounce'' a packet off a server on the net; obviously, this server must be setup to put the IP address of the sender as part of the returning packet.

DirectPlay''s NAT resolver packages such a tool, but you still need a server running it on the net somewhere for a Client/Server/Peer object to use it.

> ... so that I can tell other people what it is

How do you communicate your address? Web page? Email?

-cb

Share this post


Link to post
Share on other sites
Yes, because my school charges for the internet per assigned IP address, I have a small collection of machines that I run behind a router. Ideally I would like to run my gameserver on one of them.

NAT resolution seems to be an issue that many professional games just flat out ignore (I can''t host a lot of games behind my router). It''s unfortunate that there''s no way to talk to the router directly to get this information :-(.

Anyways, a lesser solution that will work for cases when the server is not behind a NAT is to use:

Address []addr = m_Server.GetLocalHostAddresses(LocalAddressFlags.None);
m_Form.labelServerIP.Text = "Server IP: " + addr[0].GetComponentString("hostname");

Which I mainly put here for the benefit of people trying to figure this out in the future (by running searches on this forum)


----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Coding:
http://www.stanford.edu/~jjshed/coding

Miscellany:
http://www.stanford.edu/~jjshed

Share this post


Link to post
Share on other sites
quote:
Original post by Telamon
Address []addr = m_Server.GetLocalHostAddresses(LocalAddressFlags.None);
m_Form.labelServerIP.Text = "Server IP: " + addr[0].GetComponentString("hostname");

Which I mainly put here for the benefit of people trying to figure this out in the future (by running searches on this forum)




hm..i don''t code c#, just c++..but shouldnt that just give you the ip of the machine? like 192.168.x.x if its on your internal network.

as for getting games working behind a router..tried port forwarding?

Share this post


Link to post
Share on other sites
or, you could use some dunamic dns service, and include a small "updater" for that in your server. they have source codes for that on some of the different dynamic dns services.
this way, you could have like "gameserver.myip.net" or something, that includes your ip, and it would be updated to any new ip the server is on, when the server started. this makes for a problem when running multiple servers though, and is only good for 1 main server, controlled by you.

Share this post


Link to post
Share on other sites