pyqt IP段端口扫描工具
STCP.py
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import sys
import socket
import threading,time
socket.setdefaulttimeout(10) #设置了全局默认超时时间
import thread
import ini
import time #获取时间和延时
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(272, 482)
self.textEdit = QtGui.QTextEdit(Form)
self.textEdit.setGeometry(QtCore.QRect(60, 10, 201, 31))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.textEdit_2 = QtGui.QTextEdit(Form)
self.textEdit_2.setGeometry(QtCore.QRect(60, 50, 201, 31))
self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))
self.textEdit_3 = QtGui.QTextEdit(Form)
self.textEdit_3.setGeometry(QtCore.QRect(60, 90, 81, 31))
self.textEdit_3.setObjectName(_fromUtf8("textEdit_3"))
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(10, 30, 54, 12))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(10, 70, 54, 12))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(20, 110, 54, 12))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(160, 90, 101, 31))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
#self.pushButton.clicked.connect(self.mess)
self.textEdit_4 = QtGui.QTextEdit(Form)
self.textEdit_4.setGeometry(QtCore.QRect(10, 150, 251, 321))
self.textEdit_4.setObjectName(_fromUtf8("textEdit_4"))
self.label_4 = QtGui.QLabel(Form)
self.label_4.setGeometry(QtCore.QRect(70, 130, 251, 25))
self.label_4.setObjectName(_fromUtf8("label_4"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.test)
def test(self):
thread.start_new_thread(self.mess, ())
def mess(self):
#self.label_4.setText(u"正在扫描:")
#QtGui.QMessageBox.information(None, u"消息", u"消息提示")
# data=self.textEdit_2.toPlainText() #获取内容
# QtGui.QMessageBox.information(None, u"消息",data)
ip1=self.textEdit.toPlainText() #获取内容
ip2=self.textEdit_2.toPlainText() #获取内容
port=self.textEdit_3.toPlainText() #获取内容
ini.ini_write(ip1,ip2,port) #修改INI
# if ip1>=ip2:
# self.textEdit_4.append(u"开始IP大于结束IP请重新输入")
# QtGui.QMessageBox.information(None, u"消息", u"开始IP大于结束IP请重新输入")
# return 0
self.textEdit_4.append(u"扫描结果会保存在程序目录下ip.txt")
list_ip=self.gen_ip(self.ip2num(ip1),self.ip2num(ip2))
self.pushButton.setEnabled(0) #给按钮改成禁用
self.textEdit_4.append(u"需要扫描"+str(len(list_ip))+u"个IP")
I1 = 0 #得到list的第一个元素
ip=0
self.textEdit_4.append(u"开始扫描IP--"+time.strftime('%Y.%m.%d-%H.%M.%S'))
while I1 < len(list_ip):
if ip>=200:
ini.ini_write(list_ip[I1],ini.IP2,port) #修改INI
ip=0
print list_ip[I1]
ip = ip + 1
#self.textEdit_4.append(list_ip[I1])
time.sleep(0.1) #确保先运行Seeker中的方法
thread.start_new_thread(self.socket_port,(list_ip[I1],int(port)))
I1 = I1 + 1 #一层
self.textEdit_4.append(u"IP扫描完成--"+time.strftime('%Y.%m.%d-%H.%M.%S'))
self.pushButton.setEnabled(1) #给按钮改成可用
def socket_port(self,ip,PORT):
try:
self.label_4.setText(U"正在扫描IP:"+str(ip)+u":"+str(PORT))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip,PORT))
#print ip,u":",PORT,u"端口开放"
self.textEdit_4.append(str(ip)+u":"+str(PORT)+u"端口开放")
xxx=file('ip.txt','w')
xxx.write(str(ip))
xxx.write('\n')
xxx.close()
except:
print ip,u":",PORT,u"端
补充:综合编程 , 安全编程 ,
上一个:PHP使用DES进行加密和解密
下一个:利用U盘进行软件加密的方法