Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # Form implementation generated from reading ui file 'connection.ui'
- #
- # Created by: PyQt5 UI code generator 5.11.3
- #
- # WARNING! All changes made in this file will be lost!
- from PyQt5 import QtCore, QtGui, QtWidgets
- from PyQt5 import QtCore, QtGui, QtWidgets
- from PyQt5 import *
- from PyQt5 import QtCore, QtGui, QtWidgets
- import sys
- from PyQt5.QtWidgets import *
- import getpass
- import telnetlib
- import paramiko
- import time
- class Ui_Form(object):
- def setupUi(self, Form):
- Form.setObjectName("Form")
- Form.resize(695, 431)
- Form.setStyleSheet("background-color: rgb(85, 87, 83);\n"
- "background-color: rgb(46, 52, 54);")
- self.exit_btn = QtWidgets.QPushButton(Form)
- self.exit_btn.setGeometry(QtCore.QRect(240, 310, 141, 41))
- self.exit_btn.setObjectName("exit_btn")
- self.startipedit = QtWidgets.QLineEdit(Form)
- self.startipedit.setGeometry(QtCore.QRect(150, 80, 125, 27))
- self.startipedit.setObjectName("startipedit")
- self.endipedit = QtWidgets.QLineEdit(Form)
- self.endipedit.setGeometry(QtCore.QRect(314, 76, 131, 31))
- self.endipedit.setObjectName("endipedit")
- self.netmaskedit = QtWidgets.QLineEdit(Form)
- self.netmaskedit.setGeometry(QtCore.QRect(465, 76, 131, 31))
- self.netmaskedit.setObjectName("netmaskedit")
- self.onlyipedit = QtWidgets.QLineEdit(Form)
- self.onlyipedit.setGeometry(QtCore.QRect(150, 40, 125, 27))
- self.onlyipedit.setObjectName("onlyipedit")
- self.conect_btn = QtWidgets.QPushButton(Form)
- self.conect_btn.setGeometry(QtCore.QRect(240, 270, 141, 31))
- self.conect_btn.setObjectName("conect_btn")
- self.splitter = QtWidgets.QSplitter(Form)
- self.splitter.setGeometry(QtCore.QRect(39, 40, 111, 71))
- self.splitter.setOrientation(QtCore.Qt.Vertical)
- self.splitter.setObjectName("splitter")
- self.only_ip_rd = QtWidgets.QRadioButton(self.splitter)
- self.only_ip_rd.setObjectName("only_ip_rd")
- self.range_ip_rd = QtWidgets.QRadioButton(self.splitter)
- self.range_ip_rd.setObjectName("range_ip_rd")
- self.splitter_2 = QtWidgets.QSplitter(Form)
- self.splitter_2.setGeometry(QtCore.QRect(90, 124, 521, 21))
- self.splitter_2.setOrientation(QtCore.Qt.Horizontal)
- self.splitter_2.setObjectName("splitter_2")
- self.ssh_rd = QtWidgets.QRadioButton(self.splitter_2)
- self.ssh_rd.setObjectName("ssh_rd")
- self.telnet_rd = QtWidgets.QRadioButton(self.splitter_2)
- self.telnet_rd.setObjectName("telnet_rd")
- self.console_rd = QtWidgets.QRadioButton(self.splitter_2)
- self.console_rd.setObjectName("console_rd")
- self.splitter_3 = QtWidgets.QSplitter(Form)
- self.splitter_3.setGeometry(QtCore.QRect(90, 216, 491, 31))
- self.splitter_3.setOrientation(QtCore.Qt.Horizontal)
- self.splitter_3.setObjectName("splitter_3")
- self.label = QtWidgets.QLabel(self.splitter_3)
- self.label.setObjectName("label")
- self.useer = QtWidgets.QLineEdit(self.splitter_3)
- self.useer.setObjectName("useer")
- self.label_2 = QtWidgets.QLabel(self.splitter_3)
- self.label_2.setObjectName("label_2")
- self.paass = QtWidgets.QLineEdit(self.splitter_3)
- self.paass.setObjectName("paass")
- self.splitter_4 = QtWidgets.QSplitter(Form)
- self.splitter_4.setGeometry(QtCore.QRect(130, 160, 411, 31))
- self.splitter_4.setOrientation(QtCore.Qt.Horizontal)
- self.splitter_4.setObjectName("splitter_4")
- self.brwose = QtWidgets.QPushButton(self.splitter_4)
- self.brwose.setObjectName("brwose")
- self.brooo = QtWidgets.QLineEdit(self.splitter_4)
- self.brooo.setObjectName("brooo")
- self.paass.setEchoMode(QLineEdit.Password)
- self.retranslateUi(Form)
- QtCore.QMetaObject.connectSlotsByName(Form)
- def retranslateUi(self, Form):
- _translate = QtCore.QCoreApplication.translate
- Form.setWindowTitle(_translate("Form", "fast-connect"))
- self.exit_btn.setText(_translate("Form", "exit"))
- self.conect_btn.setText(_translate("Form", "connect"))
- self.only_ip_rd.setText(_translate("Form", "only-ip"))
- self.range_ip_rd.setText(_translate("Form", "range-of-ip"))
- self.ssh_rd.setText(_translate("Form", "ssh"))
- self.telnet_rd.setText(_translate("Form", "telnet"))
- self.console_rd.setText(_translate("Form", "console "))
- self.label.setText(_translate("Form", "username"))
- self.label_2.setText(_translate("Form", "password"))
- self.brwose.setText(_translate("Form", "browse"))
- class mainapp (QWidget,Ui_Form):
- def __init__(self):
- QWidget.__init__(self)
- self.setupUi(self)
- self.exit_handle()
- self.connect_()
- self.browsing()
- # self.for_consle()
- def test(self):
- self.only_ip_rd.setChecked(True)
- self.only_ip_rd.setChecked(False)
- def connect_(self):
- self.conect_btn.clicked.connect(self.get_ip)
- def exit_handle(self):
- self.exit_btn.clicked.connect(exit)
- def browsing(self):
- self.brwose.clicked.connect(self.real_browse)
- def real_browse(self):
- global fname
- fname = QFileDialog.getOpenFileName(self,'open file' ,'/')
- self.brooo.setText(fname[0])
- def get_ip (self,):
- if self.console_rd.isChecked()==True:
- print (" can not support serial connection now ")
- #######only ip for ssh and telnet acceptable work ###################################
- if self.only_ip_rd.isChecked()== True :
- if self.telnet_rd.isChecked() == True:
- print (" now we are using telnet and only ip ")
- HOST=self.onlyipedit.text()
- print (HOST)
- username=self.useer.text()
- print (username)
- password=self.paass.text()
- print (password)
- tn = telnetlib.Telnet(HOST.encode('ascii'))
- tn.read_until(b"Username: ")
- tn.write(username.encode('ascii') + b"\n")
- if password:
- tn.read_until(b"Password: ")
- tn.write(password.encode('ascii') + b"\n")
- with open(fname[0].encode('ascii'), 'r') as f:
- for line in f:
- tn.write(line.encode('ascii'))
- #tn.write(b"wr")
- tn.write(b"exit \n")
- print(tn.read_all())
- if self.only_ip_rd.isChecked() ==True :
- if self.ssh_rd.isChecked()==True:
- print (" now we are using ssh and only ip ")
- ssh_client = paramiko.SSHClient()
- ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh_client.connect(hostname=self.onlyipedit.text(), username=self.useer.text(), password=self.paass.text())
- print("Successful connection", )
- remote_connection = ssh_client.invoke_shell()
- with open (fname[0], 'r') as f :
- for line in f :
- remote_connection.send(line ) #note you will write commands from first line t wr
- time.sleep(1)
- output = remote_connection.recv(65535)
- print(output)
- ssh_client.close
- if self.range_ip_rd.isChecked()==True:
- if self.telnet_rd.isChecked()==True:
- print (" now we will config more than ip using telnet ")
- start = self.startipedit.text()
- end = int (self.endipedit.text())+1
- networkname=str(self.netmaskedit.text())
- file = fname[0]
- user = self.useer.text()
- password = self.paass.text()
- for n in range(int(start), int(end), 1):
- print(n)
- HOST = networkname + "." + str(n)
- print(HOST)
- tn = telnetlib.Telnet(HOST)
- tn.read_until(b"Username: ")
- tn.write(user.encode('ascii') + b"\n")
- if password:
- tn.read_until(b"Password: ")
- tn.write(password.encode('ascii') + b"\n")
- tn.write(b"ena\n")
- tn.write(b"mano")
- with open(file.encode('ascii'), 'r') as f:
- for line in f:
- tn.write(line.encode('ascii'))
- tn.write(b"end \n")
- # tn.write(b"wr")
- tn.write(b"exit \n")
- print(tn.read_all())
- if self.range_ip_rd.isChecked()==True:
- if self.ssh_rd.isChecked()==True:
- print (" nwo we will config more than ip ssh ")
- start=self.startipedit.text()
- end=int (self.endipedit.text())+1
- networkname = str(self.netmaskedit.text())
- for i in range(int (start),int (end),1):
- hosname1 =networkname+"."+str(i)
- ssh_client = paramiko.SSHClient()
- ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh_client.connect(hostname=hosname1, username=self.useer.text(),password=self.paass.text())
- print("Successful connection", )
- remote_connection = ssh_client.invoke_shell()
- with open(fname[0], 'r') as f:
- for line in f:
- remote_connection.send(line) # note you will write commands from first line t wr
- time.sleep(1)
- output = remote_connection.recv(65535)
- print(output)
- ssh_client.close
- def run ():
- app = QApplication(sys.argv)
- window = mainapp()
- window.show()
- app.exec_()
- if __name__ == '__main__':
- run()
Add Comment
Please, Sign In to add comment