码迷,mamicode.com
首页 > 其他好文 > 详细

py2.7+pyqt4开发端口检测工具

时间:2014-06-20 15:41:23      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   tar   

  使用工具:python2.7,pyqt4,pyinstaller,pywin32

  先贴代码

bubuko.com,布布扣
  1 import sys
  2 from PyQt4 import QtGui,QtCore
  3 
  4 import threading
  5 import thread
  6 import os
  7 import re
  8 import urllib
  9 import socket
 10 import time
 11 
 12 
 13 global maxNum
 14 global cnt
 15 global sign
 16 
 17 class Main_QWidget(QtGui.QWidget):
 18     def __init__(self):
 19         QtGui.QWidget.__init__(self)
 20 
 21         self.ipaddr=QtGui.QLineEdit(self)
 22         self.portBegin=QtGui.QLineEdit(self)
 23         self.portEnd=QtGui.QLineEdit(self)
 24         self.GoButton=QtGui.QPushButton(Go,self)
 25         self.out=QtGui.QTextBrowser()
 26 
 27         self.ipinfo=QtGui.QLabel("input the ip : ")
 28         self.portinfo1=QtGui.QLabel("input the begin port : ")
 29         self.portinfo2=QtGui.QLabel("input the end   port : ")
 30         self.resinfo=QtGui.QLabel(" the res : ")
 31         
 32         #self.status=QtGui.QTextBrowser()
 33         
 34         grid=QtGui.QGridLayout()
 35         
 36         grid.addWidget(self.ipinfo,0,0,1,3)
 37         grid.addWidget(self.ipaddr,1,0,1,3)
 38         
 39         grid.addWidget(self.portinfo1,2,0,1,3)
 40         grid.addWidget(self.portBegin,3,0,1,3)
 41         
 42         grid.addWidget(self.portinfo2,4,0,1,3)
 43         grid.addWidget(self.portEnd,5,0,1,3)
 44         
 45         grid.addWidget(self.GoButton,6,0,1,3)
 46         
 47         grid.addWidget(self.resinfo,7,0,1,3)
 48         grid.addWidget(self.out,8,0,1,3)
 49         
 50         
 51         #grid.addWidget(self.status,5,1,1,3)
 52         
 53 
 54         self.resize(300,600)
 55         self.setLayout(grid)
 56         self.setWindowTitle("find the open port = =")
 57 
 58         self.connect(self.GoButton,QtCore.SIGNAL(clicked()),gogogo)
 59 
 60         def getIpAddr(self):
 61             return self.ipaddr.text()
 62         def getPortBegin(self):
 63             return self.portBegin.text()
 64         def getPortEnd(self):
 65             return self.portEnd.text()
 66 
 67 def gogogo1():
 68     print("hello,world\n")
 69     print("ip :",main.ipaddr.text())
 70     print("begin: ",main.portBegin.text())
 71     print("end: ",main.portEnd.text())
 72     main.out.append("??")
 73 
 74 def output(temp,interval):
 75     main.out.append("open port: "+str(temp))
 76 
 77 def tryconnect(temp,interval):
 78     global cnt
 79     global sign
 80     s=socket.socket()
 81     ttemp=int(temp)
 82     t=s.connect_ex((main.ipaddr.text(),ttemp))
 83     if t==0:
 84         sign=1
 85         #thread.start_new_thread(output,(temp,1))
 86         main.out.append("open port: "+str(ttemp))
 87         print("   find open port: ",ttemp)
 88         cnt=cnt-1
 89         thread.exit()
 90         return True
 91     else:
 92         cnt=cnt-1
 93         thread.exit()
 94         return False
 95 
 96 def sleep(temp,interval):
 97     time.sleep(1)
 98     thread.exit()
 99 
100 def gogogo():
101     global cnt
102     global maxNum
103     global sign
104     sign=0;
105     #main.GoButton.setEnabled(0)
106     main.out.append(" finding "+ main.ipaddr.text() + " open port ing...")
107     i=int(main.portBegin.text());
108     while i<=int(main.portEnd.text()):
109         print("threadnum= ", cnt,"port= ",i)
110         #main.status.append( "cnt= "+str(cnt)+"i= "+str(i) )
111         if( cnt < maxNum ):
112             thread.start_new_thread(tryconnect,(i,1))
113             i=i+1
114             cnt=cnt+1
115         #else:
116         #    thread.start_new_thread(sleep,(1,1))
117         #    time.sleep(0.1)
118         #    print("waiting...")
119     if sign==0:
120         main.out.append(" no open port in range port...")
121     #main.GoButton.setEnabled(1)
122     return True
123      
124 
125 if __name__=="__main__":
126     global maxNum
127     maxNum=800
128     global cnt
129     cnt=0
130 
131     app=QtGui.QApplication(sys.argv)
132     main=Main_QWidget()
133     main.show()
134     sys.exit(app.exec_())
135     
find_open_port

  先说说遇到的问题,我是python菜鸟,昨天用python3.4写的,然后各种找,用到啥百度啥,最后终于让我把程序写好了,后来打包成exe文件时候遇到问题了,今天上午来卸载了3.4改成了2.7,用pyinstaller打包,成了!

 

  先写这么多,到时候补充吧。

bubuko.com,布布扣

bubuko.com,布布扣

py2.7+pyqt4开发端口检测工具,布布扣,bubuko.com

py2.7+pyqt4开发端口检测工具

标签:style   class   blog   code   http   tar   

原文地址:http://www.cnblogs.com/symons1992/p/3796714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!