Continuing the theme why the tcp server does not receive an external ip address?
@avp, sorry for the pressure, but I want to deal with this topic, probably I can not ask the right question, because The answers are not quite on the topic that I mean.
I know that ipconfig provides these interfaces and that 10.0.0.0 - 10.255.255.255, 172.16.0.0 - 172.31.255.255, 192.168.0.0 - 192.168.255.255 are left for internal use. I have a dynamic IP. Both the IP and the default gateway are the same.
Both the server and the client both have a dynamic IP and access the Internet via the local network.
I will try to reformulate the question:
1. Is it possible to write a program in C ++ that will write to a variable and output data about all my interfaces and their ip to the screen (what I see in ipconfig / all), possibly without using sockets?
2. Or question 1, but using sockets? Solved part of the issue
C ++ local ip code:
#include "conio.h" #include "iostream" #include "windows.h" #include "winsock.h" int main() { WSADATA ws; hostent *h; char buf[128]; if (WSAStartup (MAKEWORD (1,1), &ws) == 0) { if (gethostname(&buf[0], 128) == 0) { printf("machine name %s \n", buf); h = gethostbyname(&buf[0]); if (h != NULL) { printf("ip local %s \n", inet_ntoa (*(reinterpret_cast<in_addr *>(*(h->h_addr_list)))) ); printf("ip global ?\n"); } else { printf("er2"); } } WSACleanup(); getch(); } return 0; }
and that still external ip deduced.
3. Maybe you need to use a proxy so that both of them know the ip of the proxy and connect to each other and transmit information through it?
4. Or write code to recognize ip through sites like myip_ru?
5. Or does my task have no solution at all?
6. Where is the interface data stored by the console when Ipconfig / all is requested? If it is possible in detail, there in the OS, in a variable, because if I see them, it means they are somehow obtained and stored somewhere.