Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5 import QtWidgets
- import getstats
- username='uname'
- password='pword'
- import telnetlib
- HOST = '192.168.0.5'
- class Window(QtWidgets.QWidget):
- def __init__(self):
- super().__init__()
- self.init_ui()
- def init_ui(self):
- self.b = QtWidgets.QPushButton('Connect')
- self.l = QtWidgets.QLabel('Not connected')
- h_box = QtWidgets.QHBoxLayout()
- h_box.addStretch()
- h_box.addWidget(self.l)
- h_box.addStretch()
- v_box = QtWidgets.QVBoxLayout()
- v_box.addWidget(self.b)
- v_box.addLayout(h_box)
- self.setLayout(v_box)
- self.setWindowTitle('PyQt5 Lesson 5')
- self.b.clicked.connect(self.btn_click)
- self.show()
- def btn_click(self):
- self.l.setText('connecting')
- tn_connect()
- def tn_connect():
- telnet = telnetlib.Telnet(HOST)
- telnet.read_until(b"Password:")
- telnet.write((password + "n").encode('ascii'))
- telnet.write(("exitn").encode('ascii'))
- telnet_out = str(telnet.read_all())
- print(telnet_out)
- a_window.l.setText('connected')
- app = QtWidgets.QApplication(sys.argv)
- a_window = Window()
- sys.exit(app.exec_())
Add Comment
Please, Sign In to add comment