-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuoteConnection.py
More file actions
56 lines (32 loc) · 1.14 KB
/
QuoteConnection.py
File metadata and controls
56 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
class Connection:
def __init__(self, timeout=10):
self.__connected = False
self.__timeout = timeout
self.__connections = []
self.__AvailableConnections()
@property
def Connected(self):
self.__ConnectionState()
return self.__connected
def __AvailableConnections(self):
path = "/sys/class/net"
for content in os.listdir(path):
if os.path.isdir(content):
self.__connections.append(content)
def __ConnectionState(self):
for connection in self.__connections:
try:
state = open(connection).read()
if state:
if int(state) == 1:
self.__connected = True
return
except OSError:
self.__connected = False
def TryConnection(self):
self.__ConnectionState()
for i in range(self.__timeout):
if self.__connected:
return self.__connected
self.__ConnectionState()