How to get my machine's IP address from Ruby without leveraging from other IP address?

后端 未结 5 488
说谎
说谎 2020-12-14 07:43

I have searched everywhere but their solution requires some form of IP address. Here are the solutions i have found.

    require \'socket\'
#METHOD 1
    ip          


        
5条回答
  •  轮回少年
    2020-12-14 08:00

    require 'socket'
    Socket::getaddrinfo(Socket.gethostname,"echo",Socket::AF_INET)[0][3]
    

    quite like method 1, actually

提交回复
热议问题