多网卡下获取网卡名称

来源:互联网 发布:帮助减肥的软件 编辑:程序博客网 时间:2024/05/10 21:24
import osimport stringinterfacename = "eth0"str1 = "ifconfig | cut -d' ' -f1 | sed '/^$/d'"str2 = "ifconfig " +interfacename+" | grep \"inet addr:\" | awk '{print $2}' | cut -c 6-"str3 = "ifconfig eth0 | grep \"inet addr:\" | awk '{print $2}' | cut -c 6- "output = os.popen(str2)strs = output.read()print type(strs)l = strs.split()print lprint "1"print strs.strip()

子网掩码转数字

exchange_mask = lambda mask: sum(bin(int(i)).count('1') \                                 for i in mask.split('.'))print(exchange_mask('255.255.0.0'))
0 0
原创粉丝点击