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
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
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
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
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
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
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
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