Network.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import configparser
  4. import socket
  5. class Network:
  6. def __init__(self):
  7. config = configparser.ConfigParser()
  8. config.read('config.ini')
  9. self.wlan = config["Network"]["wlan"]
  10. self.update = config["Network"]["wlan"]
  11. def CheckWLan(self,LanName=""):
  12. """
  13. Checks for a network
  14. :param LanName: The network name to search for
  15. :type LanName: str
  16. :return: Returns true, when the w-lan was found
  17. :rtype: boolean
  18. """
  19. import sys, subprocess, platform
  20. if LanName=="": LanName = self.wlanName
  21. cmd = subprocess.Popen('sudo iwlist scan', shell=True, stdout=subprocess.PIPE)
  22. for line in cmd.stdout:
  23. line = line.strip()
  24. if line.find(':')>-1:
  25. opt, arg = line.split(':',1)
  26. arg = arg.strip('\"')
  27. if opt == "ESSID":
  28. if(arg==LanName):
  29. return True
  30. del cmd
  31. return False
  32. @staticmethod
  33. def getIp():
  34. hostname = socket.gethostname()
  35. return socket.gethostbyname(hostname)
  36. @staticmethod
  37. def getHostName():
  38. return socket.gethostname()