import os
import string
interfacename = "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 l
print "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'))