部分代码:
# -*- coding: utf-8 -*- """Module implementing PortScan.""" from PyQt4.QtCore import pyqtSignaturefrom PyQt4.QtGui import QDialogfrom PyQt4 import QtGui,QtCorefrom Ui_PortScan import Ui_PortScanimport socketclass PortScan(QDialog, Ui_PortScan): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget (QWidget) """ QDialog.__init__(self, parent) self.setupUi(self) # QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),self.on_pushButton_clicked) @pyqtSignature("") def on_pushButton_clicked(self): for ip in self.getiplist(): self.socket_port(ip) def getiplist(self): self.startnum = int(self.ip2num(str(self.startlineEdit.text()))) self.endnum = int(self.ip2num(str(self.endlineEdit.text()))) iplist = [] for num in range(self.startnum,self.endnum+1): ip = self.num2ip(num) iplist.append(ip) return iplist def ip2num(self,ip): ip = [int(x) for x in ip.split(‘.‘)] return ip[0]<<24|ip[1]<<16|ip[2]<<8|ip[3] def num2ip(self,num): return ‘%s.%s.%s.%s‘ % ( (num & 0xff000000) >> 24, (num & 0x00ff0000) >> 16, (num & 0x0000ff00) >> 8, num & 0x000000ff) def socket_port(self,ip): port = int(self.portlineEdit.text()) try: self.messagelabel.setText(u"正在扫描IP:%s:%d..."%(ip,port)) s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect((ip,port)) self.textEdit.append(‘IP:%s:%d Open‘ % (ip,port)) except: self.textEdit.append(‘IP:%s:%d Closed‘ % (ip,port)) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) ui = PortScan() ui.show() sys.exit(app.exec_())
时间: 2024-12-27 16:09:38