예제 #1
0
def initializeInterface(interface):
    proc = subprocess.Popen(['ip', 'link', 'set',  interface, 'up' ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))
    sleep(4)
    proc = subprocess.Popen(['iw', 'dev',  interface, 'scan' ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))
    return True
예제 #2
0
def disconnectWiFi(interface, defaults):
    assert type(interface) == type('a')
    assert type(defaults) == type({})
    proc = subprocess.Popen(['killall', 'wpa_supplicant'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))

    proc = subprocess.Popen(['dhclient', '-r', interface], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))

    proc = subprocess.Popen(['ip', 'link', 'set', interface, 'down'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))

    confDefaultGW(defaults['interface'], defaults['gateway'])

    return True
예제 #3
0
def checkIP(gw):
    proc = subprocess.Popen(['ip', 'a'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    out = proc.communicate()
    out = decodeUTF8(out)
    syslog(LOG_INFO, out)
    if ''.join(['inet ', gw[0:4]]) in out:
        return True
    else:
        return False
예제 #4
0
def getBSSID(interface):
    proc = subprocess.Popen(['iw', 'dev', interface, 'link'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    out = proc.communicate()
    out = decodeUTF8(out)
    syslog(LOG_INFO, out)
    try:
        out = out.split('Connected to ')[1]
        out = out.split(' (on ')[0]
    except IndexError as e:
        syslog(LOG_INFO, e.value)

    return out
예제 #5
0
def getDBM(interface):
    proc = subprocess.Popen(['iw', 'dev', interface, 'link'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    out = proc.communicate()
    out = decodeUTF8(out)
    syslog(LOG_INFO, out)
    try:
        out = out.split('signal: ')[1]
        out = out.split(' dBm')[0]
    except:
        return 'NULL'

    return out
예제 #6
0
def doPingAvr(target, interface, count):
    proc = subprocess.Popen(['ping', ''.join(['-c', str(count)]), '-I', interface, target], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    out = proc.communicate()
    out = decodeUTF8(out)
    syslog(LOG_INFO, out)

    try:
        out = out.split(' = ')[1]
        out = out.split(' ms')[0]
        out = out.split('/')[1]
    except:
        return 0

    return out
예제 #7
0
def killPID(pid):
    assert type(pid) == type(42)
    proc = subprocess.Popen(['kill', '-9',  str(pid)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))
    return True
예제 #8
0
def confDefaultGW(interface, gw):
    proc = subprocess.Popen(['ip', 'route', 'del', 'default'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))
    proc = subprocess.Popen(['ip', 'route', 'add', 'default', 'via', gw, 'dev', interface], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    syslog(LOG_INFO, decodeUTF8(proc.communicate()))
    return True