-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
66 lines (55 loc) · 1.15 KB
/
utilities.py
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
57
58
59
60
61
62
63
64
65
66
import dumper
import re
def getHWAddr():
ifconfigData = dumper.readIFConfigDump()
s = re.search( r'HWaddr ([:,\w,\d]*)', ifconfigData, re.M|re.I)
HWaddr = ''
if s:
HWaddr = s.group(1)
return HWaddr
def getIPv4():
ifconfigData = dumper.readIFConfigDump()
s = re.search( r'inet addr:([.,\d]*)', ifconfigData, re.M|re.I)
ipv4 = '0'
if s:
ipv4 = s.group(1)
return ipv4
else:
print(interface+': Not connected');
ipConfigDump('usb0')
return getIPv4()
ifconfigData = dumper.readIFConfigDump()
s = re.search( r'inet addr:([.,\d]*)', ifconfigData, re.M|re.I)
ipv4 = '0'
if s:
ipv4 = s.group(1)
return ipv4
else:
print(interface+': Not connected');
#ipConfigDump('usb0')
return 0
def getClass():
ip = getIPv4()
s = re.search(r'([\d]*).*', ip, re.M|re.I)
if s:
x = int(s.group(1))
if x<128:
return 'A'
if x<192:
return 'B'
if x<224:
return 'C'
if x<240:
return 'D'
if x<256:
return 'E'
print('none')
def getPrefixLength(c):
if c=='a':
return 8
elif c=='b':
return 16
elif c=='c':
return 24
elif c=='d':
return 28