How to get the LAN IP address of a remote computer

The remote computer has two addresses: LAN and VPN

I tried to get the LAN IP address by running the following code:

hostent *host = gethostbyname(hostname); if (host) strcpy(ip, inet_ntoa(*((struct in_addr *)host->h_addr))); 

So, sometime it returns LAN , but sometime VPN . I know there are many addresses in the h_addr_list field, but how do I know which address is local?

I tried using GetAdaptersInfo (), it has a field to determine the local ip or not, but just return the ip address of my computer. I do not know how to get ip for a remote computer.

Someone give me some advice please!

+4
source share
3 answers

After playing with this problem, I understand that the adapters on the remote line may not be publicly available due to a security issue. Thus, we do not know exactly which IP address is the VPN.

In addition, the VPN address is created by the VPN server. Thus, this VPN address can be anything, even similar to our local IP. In other words, we can’t guess the VPN address.

0
source

According to your question, you declare that you can get the IP address of your computer and get the IP address of the remote computer, whether it is LAN or VPN. To determine which IP address on the remote computer is on your server, you can use the subnet test, I assume that your VPN is on a different subnet, and you can essentially check if the first 2-3 octets of your computer match the ip from 2-3 octets of remote ip. This is the only way to do this.

So, go through the remote IP address, as you say, you can get them and check them on the local IP address of the octets of your computer.

+2
source

The IP address of your local computer is 127.0.0.1 for RFC 1700 , as well as RFC 3330 . Just use a constant. No need to show imagination.

0
source

Source: https://habr.com/ru/post/1444715/


All Articles