-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtelnetEV.py
104 lines (96 loc) · 3.03 KB
/
telnetEV.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
# @Time :
# @File : telnetEV
# @Software:
# @Author : Kudoh
# @Email :
import time
import telnetlib
class Reset:
def __init__(self):
self.rtimeout = 1
def open(self, host, port):
tn = telnetlib.Telnet(host, port)
time.sleep(1)
tn.write("\n")
if self.readmsg(tn, "->") == 0:
tn.close()
tn = None
return tn
def resetEVG(self, host, port, cardnumber):
print("start resetEVG", host, port, cardnumber)
tn = self.open(host, port)
f = True
if tn == None:
f = False
else:
try:
if f: tn.write("EG\n")
if f and self.readmsg(tn, "]:") == 0: f = False
if f: tn.write("%s\n" % (cardnumber))
if f and self.readmsg(tn, "quit") == 0: f = False
if f: tn.write("r\n")
if f and self.readmsg(tn, "quit") == 0: f = False
if f: tn.write("r\n")
if f and self.readmsg(tn, "quit") == 0: f = False
if f: tn.write("q\n")
if f: self.readmsg(tn, "->")
r = tn.read_eager()
while r != "":
r = tn.read_eager()
tn.write("\r\n")
time.sleep(1)
except:
print("error")
tn.close()
return f
def resetEVR(self, host, port, cardnumber):
print("start resetEVR", host, port, cardnumber)
tn = self.open(host, port)
f = True
if tn == None:
f = False
else:
try:
if f: tn.write("ER\n")
if f and self.readmsg(tn, "]:") == 0: f = False
if f: tn.write("%s\n" % (cardnumber))
if f and self.readmsg(tn, "quit") == 0: f = False
if f: tn.write("r\n")
if f and self.readmsg(tn, "quit") == 0: f = False
if f: tn.write("r\n")
if f and self.readmsg(tn, "quit") == 0: f = False
if f: tn.write("q\n")
if f: self.readmsg(tn, "->")
r = tn.read_eager()
while r != "":
r = tn.read_eager()
tn.write("\r\n")
time.sleep(1)
except:
print("error")
tn.close()
return f
def resetVME(self, host, port):
print("start resetVME")
tn = self.open(host, port)
f = True
if tn is None:
f = False
else:
try:
tn.write("reboot\n")
r = tn.read_eager()
while r != "":
r = tn.read_eager()
tn.write("\r\n")
time.sleep(1)
tn.close()
except:
tn.close()
f = False
return f
def readmsg(self, tn, expected):
msg = tn.read_until(expected, self.rtimeout)
print(msg)
return len(msg)