how to get ip address of a host
-
The problem is that a host could have lots of network interfaces, and an interface could be bound to more than one IP address. And to top that, not all IP addresses will be reachable from off the machine. Some could be virtual devices, and others could be private network IP addresses. How do i know my local ip address which is currently reachable from outside network?
-
The problem is that a host could have lots of network interfaces, and an interface could be bound to more than one IP address. And to top that, not all IP addresses will be reachable from off the machine. Some could be virtual devices, and others could be private network IP addresses. How do i know my local ip address which is currently reachable from outside network?
-
Yes, i am looking for a C Program for this...
-
Yes, i am looking for a C Program for this...
-
Yes, i am looking for a C Program for this...
Hi! One of the few solutions that work relibaly are based on establishing a connection to some external website (e.g. google.com) and then checking the ip address of the local endpoint. Example: http://stackoverflow.com/questions/2674314/get-local-ip-address-using-boost-asio[^]
-
The problem is that a host could have lots of network interfaces, and an interface could be bound to more than one IP address. And to top that, not all IP addresses will be reachable from off the machine. Some could be virtual devices, and others could be private network IP addresses. How do i know my local ip address which is currently reachable from outside network?
char cNamearr[255];
gethostname(cNamearr, 255);
hostent* hp = gethostbyname(cNamearr);\_sockaddr.sin\_addr.s\_addr = \_nAdapterIp;//inet\_addr((const char\*)\_ucIpCharArr); \_sockaddr.sin\_addr.S\_un.S\_un\_b.s\_b1 = hp->h\_addr\_list\[0\]\[0\]; \_sockaddr.sin\_addr.S\_un.S\_un\_b.s\_b2 = hp->h\_addr\_list\[0\]\[1\]; \_sockaddr.sin\_addr.S\_un.S\_un\_b.s\_b3 = hp->h\_addr\_list\[0\]\[2\]; \_sockaddr.sin\_addr.S\_un.S\_un\_b.s\_b4 = hp->h\_addr\_list\[0\]\[3\];
-
Hi! One of the few solutions that work relibaly are based on establishing a connection to some external website (e.g. google.com) and then checking the ip address of the local endpoint. Example: http://stackoverflow.com/questions/2674314/get-local-ip-address-using-boost-asio[^]
Thanks Ahmad. But I have one doubt in the above solution. Suppose there are two ips configured in the system(one is through LAN and other one through USB) and we can connect external ip through one of the local ips(say through USB). Then does this solution always returns the local ip which can connect outside(USB in this case) or it will return any one ip.