Parse ifconfig to get only my IP address using Bash

后端 未结 20 1208
甜味超标
甜味超标 2020-11-30 05:04

I want to edit the bashrc file to have a simple function called \"myip\" to run. As you might guess, the function myip prints only my internal IP address of my machine.

20条回答
  •  [愿得一人]
    2020-11-30 05:38

    No need to do unportable ifconfig parsing in Bash. It's a trivial one-liner in Python:

    python -c 'import socket; print(socket.gethostbyname(socket.gethostname()))'
    

提交回复
热议问题