Tuesday, March 22, 2011

[Level 2] Get ether list by Python in Ubuntu.

#!/bin/env python
def getEtherList():
    return [x.strip() for x in \
    os.popen("ifconfig -a | \
    grep Link | grep '^[^ ]' | \
    grep -v lo | awk '{print($1)}'")\
    .readlines()]

print getEtherList()
Wish this helps.
regards,
Stanley Huang