DPlay: Finding the External IP Address of Local Machine

Started by
8 comments, last by Telamon 20 years, 3 months ago
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

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

Advertisement
www.whatismyip.com
Ok. There''s no way I''m going to have my server lookup it''s IP address from some website. If it ever goes down, I''m sunk.

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

Are you behind a NAT or a firewall or anything like that?

-=[ Megahertz ]=-
-=[Megahertz]=-
2 minutes on msdn.. sheesh..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/play/advancedtopics/nats/usingnatresolver.asp
> 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
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

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

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?

reality is only an option
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.
Try www.OstroSoft.com

This topic is closed to new replies.

Advertisement