Advertisement
renix1

Devices connected

Jan 28th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. from appJar import gui
  3. import requests
  4.  
  5.  
  6. DEFAULT_LINK = 'http://192.168.15.1/index.html' # Only for Vivo/GVT
  7.  
  8.  
  9. def acess_page():
  10.     try:
  11.         req = requests.get(DEFAULT_LINK)
  12.         return req.text
  13.     except Exception as e:
  14.         raise e
  15.  
  16. def extract_devices(content=None):
  17.     if content is not None:
  18.         soup = BeautifulSoup(content, 'lxml')
  19.         txtarea = soup.find('textarea').text.split('DHCP')
  20.         devices = [d[:d.find('MAC')] for d in txtarea]
  21.         return list(filter(lambda x: len(x)  > 1, devices))
  22.     return -1
  23.  
  24. def prettify(devices):
  25.     for d in devices:
  26.         yield('{}\n'.format(d.strip().replace('Hostname: ', '')))
  27.  
  28. content = acess_page()
  29. devices = extract_devices(content)
  30. devices = list(prettify(devices))
  31.  
  32.  
  33. class Window(gui):
  34.     """
  35.        Subclassing appJar.gui
  36.    """
  37.     def __init__(self):
  38.         super().__init__()
  39.         self.setTitle('Dispositivos conectados')
  40.         self.setResizable(False)
  41.         self.setSize(350, 200)
  42.         colours = ['white', 'black']
  43.         coloursFg = colours[::-1]
  44.         for i in range(0, len(devices)):
  45.             self.addLabel(i, devices[i], colspan=2)
  46.             self.setLabelBg(i, colours[i%2])
  47.             self.setLabelFg(i, coloursFg[i%2])
  48.         self.addWebLink("Clique aqui para informações em tempo real", DEFAULT_LINK)
  49.         self.go()
  50.  
  51. Window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement