Skip to main content
gamedev.net
🔒 Locked

IP number

Started by bartiss Feb 14, 2007 at 12:37 PM 3 replies 1.2k views
Original Post
bartiss
bartiss
Hi, Is there an easy way to obtain current IP number of my computer from code? I've managed to launch DirectInput server, but have no idea how to do that. Maybye there is a Windows function for this? Best Regards
rip-off
rip-off
You probably can, but I wouldn't do it depending on why you need the ip address. Due to NATs the address you get may not be publically addressable and you may need to use some form of NAT punch through to overcome this. To get your external IP you will need to bounce a query off an external server.
bartiss
bartiss
Ok, but I assume user knows that only local network IP is necessary.

So basically, I need to get the same IP you can see when you check your connection settings under Windows.
Xai
Xai
1 more wrinkle ... a computer may have more than 1 IP address. Many current motherboards have dual NICs built-in, and of course many more people use wireless. Which also means the IP can change at any time. Much like USB hotplugging, there are API calls to be notified of such changes though.

Ignoring all that though ...

very usefull information for Win32 API winsock programming can be found here:

http://tangentsoft.net/wskfaq/intermediate.html

primarily at section 3.3 "How do I get my IP address from within a Winsock program?"

you will see of course the sample program involves a loop ... which cannot easily be ignored - but you can safely ignore the adding, removing, changing of the information while your running ... for now at least.

bartiss
bartiss
Thank you very much for this information!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.