python 获取本机内网网卡所有 ip

具体代码如下,输出结果示例如:

127.0.0.1||::1||fe80::1||fe80::aede:48ff:fe00:1122||fe80::56:c4b:680b:b9ce||fd00:1:c:1021:b34b:2be5:5425:62b
import os

def get_local_ip_str(sep = "||"):
    cmd = " ifconfig | grep inet | awk -F" |t" '{print $3}' | awk -F"%" '{print $1}' "
    b = os.popen(cmd)
    s = b.read().strip("n")
    s = s.replace("n", sep).replace("t",'')
    return s

print(get_local_ip_str('||'))