Advertisement

get user ip

Started by April 08, 2001 01:23 AM
5 comments, last by djsteffey 23 years, 5 months ago
Does anyone know a function to return the users current ip address like "127.0.0.1" (abvioulsy that is loopback address but you get the point) as a char array or something i can convert to a char array (string, CString, etc) I want to be able to display the users ip address to him. "I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma." - Mr. T
Since I''d really like to know the answer to this also, I''ll bump this back up . <bump>

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
Advertisement
Depends.

A script running on a web server can return the REMOTE_ADDR property from the server environmental variables.
Where do you want to do this? ( ie from a webpage, from DirectPlay, from Winsock ... )

If it''s from winsock then just use the inet_ntoa() function.




-------
Andrew
char FAR * inet_ntoa (
struct in_addr in
);
ok....but how do i fill in the in_addr if i dont know what their address is ?


"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
This should get all the user's IP's except the localhost. Put them in a null terminated string. WinSock should be initialized first:

    int i = 0;char HostName[32];HOSTENT * HostInfo;char * LocalIPs[5] = {NULL};// Get IP Addresses of local computergethostname(HostName, 32);HostInfo = gethostbyname(HostName);while((IsBadStringPtr(HostInfo->h_addr_list[i], 4) == 0) && (i < 5)){	LocalIPs[i] = new char[16];	sprintf(LocalIPs[i], "%i.%i.%i.%i", 	short(unsigned char(HostInfo->h_addr_list[i][0])),	short(unsigned char(HostInfo->h_addr_list[i][1])),		short(unsigned char(HostInfo->h_addr_list[i][2])),		short(unsigned char(HostInfo->h_addr_list[i][3])));	i++;}    


Good luck,

Jasper

Edited by - JasperW on April 9, 2001 5:35:57 PM
Advertisement
How do I get the client IP from DirectPlay8''s server?

This topic is closed to new replies.

Advertisement