0

I am looking for some method to obtain my laptop local IP address (eg. 192.168.1.x )using boost::asio. Via google, I only reached SJI's answer.

I am just wondering whether there are some other better options, as I think the SJI's solution might be inefficient. In order to get local IP address, SJI's solution has to set up a connected socket with remote server (google), and then obtains local_address from the connected socket.

  1. Is there any other way to get local IP without setup connection with remote server using boost::asio. In many times, no public network access for me.
  2. Can SJI's method also work for local network (i.e., my laptop is in a local network without public Internet access), and returns the local IP address (i.e., 192.168.1.X ) instead of ISP's IP address?

Thanks

shijie xu
  • 1,975
  • 21
  • 52
  • You can do platform specific solutions, on a UNIX system [getifaddrs](http://man7.org/linux/man-pages/man3/getifaddrs.3.html) should work for example. Using `ifconfig` seems like another portable option for most posix systems. – super May 26 '18 at 11:23
  • I know the dupe isn't exactly dupe, but the answer clearly confirms Asio doesn't have it. Instead, see https://stackoverflow.com/questions/212528/get-the-ip-address-of-the-machine/265978#265978 for actual code. – sehe May 26 '18 at 12:08

0 Answers0