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

后端 未结 5 495
说谎
说谎 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 07:56

    parse the output of the ip command?

    from https://gist.github.com/henriquemenezes/a99f13da957515023e78aea30d6c0a48

    gw = `ip route show`[/default.*/][/\d+\.\d+\.\d+\.\d+/]
    

    or parse the output of the ipconfig command: https://stackoverflow.com/a/12632929/32453

提交回复
热议问题