PUBLIC IP & server connection

to get public ip address of the system using win32 coding..
getting problem in connecting to the server.
To get public IP address just make your web server respond with this information. From your application just connect to the web server and read the response using libcurl or sockets or whatever.
Hi Venky,

I too had this problem before but sadly that's the way it is. You can use this code snippet to find the Internel\IPv4 Address like IPCONFIG/ALL but not the public IP.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<Windows.h>  
#include<iostream>
#pragma comment(lib,"ws2_32.lib")
int main()
{ 
WSAData wsaData; 
WSAStartup(MAKEWORD(2,2),&wsaData);
HOSTENT* Host;
char hostname[128] = {0};
char* IPv4 = new char[128];
gethostname(hostname, 128);
Host = gethostbyname(hostname);
IPv4 = inet_ntoa(*(in_addr*)Host->h_addr_list[0]);
std::cout<<IPv4<<endl;
std::cin.get();
WSACleanup();
return 0;
}


Apart from that you can go with what modoran said:
"To get public IP address just make your web server respond with this information. From your application just connect to the web server and read the response using libcurl or sockets or whatever."


Kind Regards,
SpaceWorm
Last edited on
Thankq for your rply SpaceWorm.

i have already have written coding for IPCONFIG/ALL , now i want PUBLIC IP address only BY CONNECTING THROUGH SERVER(Because i have already written the code to get PUBLIC IP through short cut process, but that is not Standard process).

and your suggestion for getting public ip is useful for me thq again.
Last edited on
Thankq for your rply modoran.


your suggestion for getting public ip is useful for me, but im getting problem with connecting web server only.
Hi,

I suggest you learn by using Wininet. Which is very useful this for this.
Topic archived. No new replies allowed.