python3 小工具
扫描IP的端口是否开放:Porttest.py
1 # -*- coding: utf-8 -*- 2 import sys 3 import os 4 import socket 5 6 #扫描 7 def scanport(ip,port): 8 try: 9 socket.setdefaulttimeout(2) 10 s=socket.socket() 11 s.connect((ip,port)) 12 portrecv=s.recv(1024) 13 return portrecv 14 except Exception as e: 15 print(e) 16 17 ''' 18 检测ip的合法性 19 filter(fuction, list)检查list中符合fuction的元素 20 ''' 21 def ip_check(ip): 22 q = ip.split('.') 23 return len(q)==4 and len(list(filter(lambda x: x>=0 and x<= 255, list(map(int, filter(lambda x: x.isdigit(), q))))))==4 24 25 def main(): 26 if len(sys.argv)==2: 27 ip=sys.argv[1] 28 portlist=[21,22,25,80,110,443] 29 if ip_check(ip)==0: 30 print("输入的不是一个合法的ip") 31 return 32 for port in portlist: 33 portcheck=scanport(ip,port) 34 if portcheck: 35 print(str(ip)+':'+str(portchec1)) 36 else: 37 print("Tips:python3 Porttest.py 目标ip\n") 38 39 if __name__=='__main__': 40 main()
生成各种进制的IP:IP Converter.py
1 # -*- coding: utf-8 -*- 2 import sys 3 import socket 4 import struct 5 import itertools 6 7 #纯8进制 8 def ip_split_by_comma_oct(ip): 9 """ 10 set函数是一个无序不重复的元素集,用于关系测试和去重 11 print ip_split_oct -> ['0177', '0', '0', '01'] 12 print parsed_result -> set(['0177.0.0.01']) 13 """ 14 parsed_result = set() 15 ip_split = str(ip).split('.') 16 ip_split_oct = [oct(int(_)) for _ in ip_split] 17 parsed_result.add('.'.join(ip_split_oct)) 18 return parsed_result 19 20 #纯16进制 21 def ip_split_by_comma_hex(ip): 22 """ 23 print ip_split_hex -> ['0x7f', '0x0', '0x0', '0x1'] 24 print parsed_result -> set(['0x7f.0x0.0x0.0x1']) 25 """ 26 parsed_result = set() 27 ip_split = str(ip).split('.') 28 ip_split_hex = [hex(int(_)) for _ in ip_split] 29 parsed_result.add('.'.join(ip_split_hex)) 30 return parsed_result 31 32 #10进制,8进制 33 def combination_oct_int_ip(ip): 34 """ 35 itertools.combinations(iterable,r) 36 创建一个迭代器,返回iterable中长度为r的序列。 37 print oct_2 -> [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] 38 print oct_3 -> [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)] 39 enumerate用来枚举函数 40 tuple表示元组 41 """ 42 result = set() 43 parsed_result = set() 44 ip_split = str(ip).split('.') 45 oct_2 = list(itertools.combinations([0, 1, 2, 3], 2)) 46 oct_3 = list(itertools.combinations([0, 1, 2, 3], 3)) 47 #变化ip的一段 48 for n, _ in enumerate(ip_split): 49 _tmp = oct(int(_)) 50 #ip_split[:n] -> []读取前面的数 ip_split[n+1:]-> ['0', '0', '1']读取后面的数 51 _delete = ip_split[:n] + ip_split[n+1:] 52 _delete.insert(n, _tmp) 53 result.add(tuple(_delete)) 54 #变化ip的两段 55 for _ in oct_2: 56 _tmp_ip = ip_split[:] 57 _tmp1 = oct(int(ip_split[_[0]])) 58 _tmp2 = oct(int(ip_split[_[1]])) 59 del _tmp_ip[_[0]] 60 del _tmp_ip[_[1]-1] 61 _tmp_ip.insert(_[0], _tmp1) 62 _tmp_ip.insert(_[1], _tmp2) 63 result.add(tuple(_tmp_ip)) 64 #变化ip的三段 65 for _ in oct_3: 66 _tmp_ip = ip_split[:] 67 _tmp1 = oct(int(ip_split[_[0]])) 68 _tmp2 = oct(int(ip_split[_[1]])) 69 _tmp3 = oct(int(ip_split[_[2]])) 70 del _tmp_ip[_[0]] 71 del _tmp_ip[_[1] - 1] 72 del _tmp_ip[_[2] - 2] 73 _tmp_ip.insert(_[0], _tmp1) 74 _tmp_ip.insert(_[1], _tmp2) 75 _tmp_ip.insert(_[2], _tmp3) 76 result.add(tuple(_tmp_ip)) 77 for _ in result: 78 parsed_result.add('.'.join(_)) 79 return parsed_result 80 81 #16进制,10进制 82 def combination_hex_int_ip(ip): 83 """ 84 :param ip: 85 :return: 86 """ 87 result = set() 88 parsed_result = set() 89 ip_split = str(ip).split('.') 90 hex_2 = list(itertools.combinations([0, 1, 2, 3], 2)) 91 hex_3 = list(itertools.combinations([0, 1, 2, 3], 3)) 92 for n, _ in enumerate(ip_split): 93 _tmp = hex(int(_)) 94 _delete = ip_split[:n] + ip_split[n+1:] 95 _delete.insert(n, _tmp) 96 result.add(tuple(_delete)) 97 for _ in hex_2: 98 _tmp_ip = ip_split[:] 99 _tmp1 = hex(int(ip_split[_[0]])) 100 _tmp2 = hex(int(ip_split[_[1]])) 101 del _tmp_ip[_[0]] 102 del _tmp_ip[_[1] - 1] 103 _tmp_ip.insert(_[0], _tmp1) 104 _tmp_ip.insert(_[1], _tmp2) 105 result.add(tuple(_tmp_ip)) 106 for _ in hex_3: 107 _tmp_ip = ip_split[:] 108 _tmp1 = hex(int(ip_split[_[0]])) 109 _tmp2 = hex(int(ip_split[_[1]])) 110 _tmp3 = hex(int(ip_split[_[2]])) 111 del _tmp_ip[_[0]] 112 del _tmp_ip[_[1] - 1] 113 del _tmp_ip[_[2] - 2] 114 _tmp_ip.insert(_[0], _tmp1) 115 _tmp_ip.insert(_[1], _tmp2) 116 _tmp_ip.insert(_[2], _tmp3) 117 result.add(tuple(_tmp_ip)) 118 for _ in result: 119 parsed_result.add('.'.join(_)) 120 return parsed_result 121 122 #10进制,16进制,8进制 123 def combination_hex_int_oct_ip(ip): 124 """ 125 :param ip: 126 :return: 127 """ 128 result = set() 129 parsed_result = set() 130 ip_split = str(ip).split('.') 131 hex_3 = list(itertools.combinations([0, 1, 2, 3], 3)) 132 for n1, n2, n3 in hex_3: 133 _tmp_ip = ip_split[:] 134 _tmp_2 = oct(int(_tmp_ip[n2])) 135 _tmp_3 = hex(int(_tmp_ip[n3])) 136 del _tmp_ip[n2] 137 del _tmp_ip[n3 - 1] 138 _tmp_ip.insert(n2, _tmp_2) 139 _tmp_ip.insert(n3, _tmp_3) 140 result.add(tuple(_tmp_ip)) 141 for _ in result: 142 parsed_result.add('.'.join(_)) 143 return parsed_result 144 145 ''' 146 socket.inet_aton() 把IPV4地址转化为32位打包的二进制格式 -> 检查是否为ipv4 147 struct.unpack(fmt,string) 按照给定的格式(fmt)解析字节流string,返回解析出来的tuple 148 !L: ! = network(=big-endian) L = unsigned long 149 ''' 150 if __name__ == '__main__': 151 if len(sys.argv)==2: 152 ip = sys.argv[1] 153 ip_int = struct.unpack('!L', socket.inet_aton(ip))[0] 154 ip_oct_no_comma = oct(ip_int) 155 ip_hex_no_comma = hex(ip_int) 156 ip_oct_by_comma = ip_split_by_comma_oct(ip) 157 ip_hex_by_comma = ip_split_by_comma_hex(ip) 158 all_result = ip_oct_by_comma | ip_hex_by_comma | combination_oct_int_ip(ip) | combination_hex_int_ip(ip) | combination_hex_int_oct_ip(ip) 159 print ip_int 160 print ip_oct_no_comma 161 print ip_hex_no_comma 162 for _ip in all_result: 163 print _ip 164 else: 165 print("Tips: IP.py 127.0.0.1 \n") 166
爆破解压zip文件:ZIP.py
1 # -*- coding:utf-8 -*- 2 import sys 3 import zipfile 4 import threading 5 6 def extractFile(zFile,password): 7 try: 8 zFile.extractall(pwd=password.encode("utf-8")) 9 print("Password is: "+password) 10 except Exception as e: 11 print(str(e)) 12 13 def main(): 14 if len(sys.argv) == 3: 15 zFile = zipfile.ZipFile(sys.argv[1]) 16 passFile = open(sys.argv[2]) 17 for line in passFile.readlines(): 18 password = line.strip('\n') 19 t = threading.Thread(target=extractFile,args=(zFile,password)) 20 t.start() 21 else: 22 print("Tips:python3 ZIP.py 要爆破的文件 字典") 23 24 if __name__ =='__main__': 25 main()
学习和总结
python绝技:运用python成为顶级黑客
一个生成各种进制格式IP的小工具:http://www.freebuf.com/sectool/140982.html
转载于:https://www.cnblogs.com/QKSword/p/8394956.html
python3 小工具相关推荐
- Python3下载图像小工具
<Python3下载图像小工具> 每次想下载图片的时候都需要到网上找相关的小段程序,奈何每次水军太多,甄别需要浪费时间,不如自己备份一个用起来方便. Key Words:python3 ...
- 利用Python3开发一款小工具(界面的设计)
前面在<利用Python3开发一款小工具(引言)>文章中,对我们的需求进行了分析.为了能够让用户运行该工具,因此我们需要一个ui界面,而python中常用的工具就是pyqt,本文将使用py ...
- 用python3+ PyQt5写一个NFC模块的串口小工具的一星期
用python3+ PyQt5写一个NFC模块的串口小工具的一星期 原因始于我们的小团队,没有写Windows上位机的人才.自己的[NFC读读写模](https://shop165836966.tao ...
- [python运维] 使用python3制作一个mysql压测小工具!
0x01 argparse模块 argparse是Python 标准库中推荐的命令行解析模块,他可以实现给出参数提示和接收用户输入的参数,类似linux的命令行功能: [root@yun ...
- Python3下Web下载媒体小工具(常用来下B站视频)
Python3下Web下载媒体小工具(常用来下B站视频) 项目地址:https://github.com/soimort/you-get 使用条件 需要以下依赖项: Python 3.2或以上 FFm ...
- python日志分析工具_基于Python3的Web日志分析小工具
PyWebLog 网站日志分析小工具 环境 Python3.5 Mysql 预览 安装 pip install pymysql pip install flask 导入日志 python Log.py ...
- 最火Python3 玩转实用小工具
课程目录: 第1章 课程介绍 介绍课程的主要内容,课程内容安排. 1-1 最火python3玩转实用小工具课程导学. 第2章 自主研发-购书比价工具 首先做好知识储备,讲解JSON.xpath.re ...
- 利用Python3开发一款小工具(环境配置)
前面一篇文章对开发的小工具的需求进行了分析,已经大致清楚了我们需要使用的工具,本文将逐个工具进行安装配置,主要包括: 1.python36安装 2.pycharm安装 3.pyqt5与pyqt5-to ...
- 实用小工具-----python3 pdf2docx轻松搞定pdf转word
轻松搞定简单版本非图片pdf转doc 轻松搞定简单版本非图片pdf转doc 在我们工作学习中,遇到很多pdf文件,无法编辑,针对这个问题我,我们用python 的pdf2doc就能很好的解决这个问题, ...
最新文章
- 如何对 Rocksdb以及类似存储引擎社区 提出 有效的性能问题?
- 在建工程的管理是怎样在总帐中实现
- html页面怎么解决跨域问题,前端web开发html如何避免js的跨域访问
- CV《物体识别与检测4 - 人脸验证》
- C++开源矩阵计算工具——Eigen 在VS2005中的下载、配置与使用
- BZOJ1305 [CQOI2009]dance跳舞 【网络流】
- 安装mysql数据库及问题解决方法
- 智乃酱的区间乘积(前缀积+逆元)
- Linux下exec函数族比如execve等函数的基本使用
- clear与resize
- python画猫咪老师_夏目友人帐 | 绘画小白怎样用水彩画一只圆滚滚的猫咪老师?...
- 常用颜色的RGB值及中英文名称
- C Primer Plus 第十章学习总结……2015.4.30
- AutoCAD2014下载和安装教程(官方中文完整版)
- 连载《阿里巴巴·马云》4 : 他就像一个鬼鬼祟祟的坏人
- 从session里面取得值为null
- c语言一维数组教学设计,C语言教学中一维数组教学设计.doc
- 一个TCP长连接设备管理后台工程(四)---jtt808协议解析
- 滚球法(Ball Pivoting)三维表面重建论文笔记
- 我的北漂之路 北漂如饮水,冷暖自知
热门文章
- python的字符串类型_python如何判断某变量是否为字符串类型
- 使用php函数判断数字,PHP 几个常用数字判断函数的简单示例
- linux能力集机制,linux能力机制
- python第四章单元测试_MOOC选修课答案第四章单元测试答案_Sar编程基础期末答案...
- linux cadence快捷键,如何设置Cadence 16.6中PCB Editor的快捷键
- python 超高精度除法_Python十进制-除法,舍入,精度
- action中的动态方法调用
- Redis入门到高可用(十一)—— 慢查询
- AMD的Naples改名为EYPC
- Spring Cache 介绍