Beispiel #1
0
def receiveMac(interface="eth0"):
    """Get MAC from interface"""
    ipconfigProg = checkUtils('/sbin/ifconfig')
    ifconfig = process(ipconfigProg,interface)
    res = re.search(r"(?:HWaddr|ether)\s(\S+)",ifconfig.read(),re.S)
    if res:
        return res.group(1)
    else:
        return "00:00:00:00:00:00"
Beispiel #2
0
def getIpAndMask(interface="eth0"):
    """Get ip and mask from interface"""
    ipconfigProg = checkUtils('/sbin/ifconfig')
    ifconfig = process(ipconfigProg,interface)
    res = re.search(r"inet(?: addr:| )(\S+)\s.*(?:Mask:|netmask )(\S+)",
                    ifconfig.read(),re.S)
    if res:
        return res.groups()
    else:
        return ("","")
Beispiel #3
0
def getRouteTable(onlyIface=[]):
    """Get route table, exclude specifed iface"""
    ipProg = checkUtils('/sbin/ip')
    routes = process(ipProg,"route")
    if onlyIface:
        filterRe = re.compile("|".join(map(lambda x:r"dev %s"%x,onlyIface)))
        routes = filter(filterRe.search,routes)
    for line in routes:
        network,op,line = line.partition(" ")
        routeParams = map(lambda x:x.strip(),line.split())
        # (network,{'via':value,'dev':value})
        if network:
            yield (network,dict(zip(routeParams[0::2],routeParams[1::2])))