#!/usr/bin/env python # -*- coding: utf-8 -*- import configparser import socket class Network: def __init__(self): config = configparser.ConfigParser() config.read('config.ini') self.wlan = config["Network"]["wlan"] self.update = config["Network"]["wlan"] def CheckWLan(self,LanName=""): """ Checks for a network :param LanName: The network name to search for :type LanName: str :return: Returns true, when the w-lan was found :rtype: boolean """ import sys, subprocess, platform if LanName=="": LanName = self.wlanName cmd = subprocess.Popen('sudo iwlist scan', shell=True, stdout=subprocess.PIPE) for line in cmd.stdout: line = line.strip() if line.find(':')>-1: opt, arg = line.split(':',1) arg = arg.strip('\"') if opt == "ESSID": if(arg==LanName): return True del cmd return False @staticmethod def getIp(): hostname = socket.gethostname() return socket.gethostbyname(hostname) @staticmethod def getHostName(): return socket.gethostname()