代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Python
】
写的IP段扫描
作者:
飞龙321
/ 发布于
2012/11/19
/
918
# -*- 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"端口未开放" #self.textEdit_4.append(ip) #---------------------------------------------------------------- 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): if num>=IPend: self.textEdit_4.append(u"IP导入数组完成") return '%s.%s.%s.%s' % ( (num & 0xff000000) >> 24, (num & 0x00ff0000) >> 16, (num & 0x0000ff00) >> 8, num & 0x000000ff ) def gen_ip(self,Aip1,Aip2): #返回数组 global IPend IPend=Aip2 return [self.num2ip(num) for num in range(Aip1,Aip2+1) if num & 0xff] #---------------------------------------------------------------- def iniA(self): ini.ini_get() #读取INI self.textEdit.setPlainText(ini.IP1) self.textEdit_2.setPlainText(ini.IP2) self.textEdit_3.setPlainText(ini.port) def retranslateUi(self, Form): Form.setWindowTitle(QtGui.QApplication.translate("Form", "QQ316118740", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("Form", "开始IP:", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("Form", "结束IP:", None, QtGui.QApplication.UnicodeUTF8)) self.label_3.setText(QtGui.QApplication.translate("Form", "端口:", None, QtGui.QApplication.UnicodeUTF8)) self.pushButton.setText(QtGui.QApplication.translate("Form", "开始扫描", None, QtGui.QApplication.UnicodeUTF8)) self.label_4.setText(QtGui.QApplication.translate("Form", "扫描结果--pyqt端口扫描器", None, QtGui.QApplication.UnicodeUTF8)) class Start(QtGui.QMainWindow): def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.ui=Ui_Form()#这儿跟上面那个class一样 self.ui.setupUi(self) self.ui.iniA() if __name__=="__main__": app=QtGui.QApplication(sys.argv) myapp=Start() myapp.show() sys.exit(app.exec_()) #!/usr/local/bin/python #-*- coding: UTF-8 -*- ################################################## #qq:316118740 #BLOG:http://hi.baidu.com/alalmn # Python 操作ini文件 # 刚学写的不好请大家见谅 ################################################## IP1="" #扫描IP IP2="" #当前已经扫到的IP port="" #扫描端口 INITXT="IP.ini" #INI文件名字 import ConfigParser def ini_get(): #读取INI try: global IP1 global IP2 global port global INITXT config = ConfigParser.ConfigParser() config.readfp(open(INITXT)) IP1 = config.get("ipdata","ip1") IP2 = config.get("ipdata","ip2") port = config.get("ipdata","port") except: print "读取INI错误" ini_add("","","") #写入INI def ini_add(ip1,ip2,pt): #写入INI try: global INITXT config = ConfigParser.ConfigParser() config.add_section("ipdata")# 设置section段及对应的值 config.set("ipdata","ip1",ip1) config.set("ipdata","ip2",ip2) config.set("ipdata","port",pt) config.write(open(INITXT, "w"))# 写入文件 except: print "写入INI错误" def ini_write(ip1,ip2,pt): #修改INI try: global INITXT config = ConfigParser.ConfigParser() config.read(INITXT) if not config.has_section("ipdata"):#看是否存在该Section,不存在则创建 temp = config.add_section("") config.set("ipdata","ip1",ip1) config.set("ipdata","ip2",ip2) config.set("ipdata","port",pt) config.write(open(INITXT, "r+")) except: print "修改INI错误" ini_add("","") #写入INI #if __name__=='__main__': ## ini_get() #读取INI ## print IP1 ## print IP2 # ## ini_add("222222222","3333333333333") #写入INI ## ini_get() #读取INI ## print IP1 ## print IP2 # # ini_write("999999999","0000000000") #修改INI # ini_get() #读取INI # print IP1 # print IP2 # -*- coding: utf-8 -*- #windows #无控制台 #console #有控制台 from distutils.core import setup import py2exe #setup(version = "1.0",description = "QQ:892768447", # name = "STCP",zipfile=None, # windows=[{"script": "STCP.py", "icon_resources": [(1, "windowws.ico")]}], # options={"py2exe":{"includes":["sip"]}}, # includes = ["ini.py"]) #setup(options={"py2exe": {"dll_excludes":["MSVCP90.dll"],}}, #windows=[{"script": "STCP.py"}, "icon_resources": [(1, "App.ico")]}], #options={"py2exe":{"includes":["exe"]}}, # includes = ["ini.py"]) setup(version = "1.0",description = "QQ:",name = "STCP",zipfile=None,windows=[{"script": "STCP.py", "icon_resources": [(1, "App.ico")]}],options={"py2exe":{"dll_excludes":["MSVCP90.dll"],"includes":["sip"]}},includes = ["ini.py"])
试试其它关键字
IP段扫描
同语言下
.
比较两个图片的相似度
.
过urllib2获取带有中文参数的url内容
.
不下载获取远程图片的宽度和高度及文件大小
.
通过qrcode库生成二维码
.
通过httplib发送GET和POST请求
.
Django下解决小文件下载
.
遍历windows的所有窗口并输出窗口标题
.
根据窗口标题调用窗口
.
python 抓取搜狗指定公众号
.
pandas读取指定列
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
飞龙321
贡献的其它代码
(
5
)
.
写的IP段扫描
.
读取TXT到数组 列表去重
.
查看FTP是否能连接成功
.
python 域名转IP 在查看制定端口是否开放
.
Python 扫描IP段 指定端口是否开放
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3