python3 小工具
扫描IP的端口是否开放:Porttest.py
# -*- coding: utf-8 -*-
import sys
import os
import socket #扫描
def scanport(ip,port):
try:
socket.setdefaulttimeout(2)
s=socket.socket()
s.connect((ip,port))
portrecv=s.recv(1024)
return portrecv
except Exception as e:
print(e) '''
检测ip的合法性
filter(fuction, list)检查list中符合fuction的元素
'''
def ip_check(ip):
q = ip.split('.')
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 def main():
if len(sys.argv)==2:
ip=sys.argv[1]
portlist=[21,22,25,80,110,443]
if ip_check(ip)==0:
print("输入的不是一个合法的ip")
return
for port in portlist:
portcheck=scanport(ip,port)
if portcheck:
print(str(ip)+':'+str(portchec1))
else:
print("Tips:python3 Porttest.py 目标ip\n") if __name__=='__main__':
main()
生成各种进制的IP:IP Converter.py
# -*- coding: utf-8 -*-
import sys
import socket
import struct
import itertools #纯8进制
def ip_split_by_comma_oct(ip):
"""
set函数是一个无序不重复的元素集,用于关系测试和去重
print ip_split_oct -> ['0177', '0', '0', '01']
print parsed_result -> set(['0177.0.0.01'])
"""
parsed_result = set()
ip_split = str(ip).split('.')
ip_split_oct = [oct(int(_)) for _ in ip_split]
parsed_result.add('.'.join(ip_split_oct))
return parsed_result #纯16进制
def ip_split_by_comma_hex(ip):
"""
print ip_split_hex -> ['0x7f', '0x0', '0x0', '0x1']
print parsed_result -> set(['0x7f.0x0.0x0.0x1'])
"""
parsed_result = set()
ip_split = str(ip).split('.')
ip_split_hex = [hex(int(_)) for _ in ip_split]
parsed_result.add('.'.join(ip_split_hex))
return parsed_result #10进制,8进制
def combination_oct_int_ip(ip):
"""
itertools.combinations(iterable,r)
创建一个迭代器,返回iterable中长度为r的序列。
print oct_2 -> [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
print oct_3 -> [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
enumerate用来枚举函数
tuple表示元组
"""
result = set()
parsed_result = set()
ip_split = str(ip).split('.')
oct_2 = list(itertools.combinations([0, 1, 2, 3], 2))
oct_3 = list(itertools.combinations([0, 1, 2, 3], 3))
#变化ip的一段
for n, _ in enumerate(ip_split):
_tmp = oct(int(_))
#ip_split[:n] -> []读取前面的数 ip_split[n+1:]-> ['0', '0', '1']读取后面的数
_delete = ip_split[:n] + ip_split[n+1:]
_delete.insert(n, _tmp)
result.add(tuple(_delete))
#变化ip的两段
for _ in oct_2:
_tmp_ip = ip_split[:]
_tmp1 = oct(int(ip_split[_[0]]))
_tmp2 = oct(int(ip_split[_[1]]))
del _tmp_ip[_[0]]
del _tmp_ip[_[1]-1]
_tmp_ip.insert(_[0], _tmp1)
_tmp_ip.insert(_[1], _tmp2)
result.add(tuple(_tmp_ip))
#变化ip的三段
for _ in oct_3:
_tmp_ip = ip_split[:]
_tmp1 = oct(int(ip_split[_[0]]))
_tmp2 = oct(int(ip_split[_[1]]))
_tmp3 = oct(int(ip_split[_[2]]))
del _tmp_ip[_[0]]
del _tmp_ip[_[1] - 1]
del _tmp_ip[_[2] - 2]
_tmp_ip.insert(_[0], _tmp1)
_tmp_ip.insert(_[1], _tmp2)
_tmp_ip.insert(_[2], _tmp3)
result.add(tuple(_tmp_ip))
for _ in result:
parsed_result.add('.'.join(_))
return parsed_result #16进制,10进制
def combination_hex_int_ip(ip):
"""
:param ip:
:return:
"""
result = set()
parsed_result = set()
ip_split = str(ip).split('.')
hex_2 = list(itertools.combinations([0, 1, 2, 3], 2))
hex_3 = list(itertools.combinations([0, 1, 2, 3], 3))
for n, _ in enumerate(ip_split):
_tmp = hex(int(_))
_delete = ip_split[:n] + ip_split[n+1:]
_delete.insert(n, _tmp)
result.add(tuple(_delete))
for _ in hex_2:
_tmp_ip = ip_split[:]
_tmp1 = hex(int(ip_split[_[0]]))
_tmp2 = hex(int(ip_split[_[1]]))
del _tmp_ip[_[0]]
del _tmp_ip[_[1] - 1]
_tmp_ip.insert(_[0], _tmp1)
_tmp_ip.insert(_[1], _tmp2)
result.add(tuple(_tmp_ip))
for _ in hex_3:
_tmp_ip = ip_split[:]
_tmp1 = hex(int(ip_split[_[0]]))
_tmp2 = hex(int(ip_split[_[1]]))
_tmp3 = hex(int(ip_split[_[2]]))
del _tmp_ip[_[0]]
del _tmp_ip[_[1] - 1]
del _tmp_ip[_[2] - 2]
_tmp_ip.insert(_[0], _tmp1)
_tmp_ip.insert(_[1], _tmp2)
_tmp_ip.insert(_[2], _tmp3)
result.add(tuple(_tmp_ip))
for _ in result:
parsed_result.add('.'.join(_))
return parsed_result #10进制,16进制,8进制
def combination_hex_int_oct_ip(ip):
"""
:param ip:
:return:
"""
result = set()
parsed_result = set()
ip_split = str(ip).split('.')
hex_3 = list(itertools.combinations([0, 1, 2, 3], 3))
for n1, n2, n3 in hex_3:
_tmp_ip = ip_split[:]
_tmp_2 = oct(int(_tmp_ip[n2]))
_tmp_3 = hex(int(_tmp_ip[n3]))
del _tmp_ip[n2]
del _tmp_ip[n3 - 1]
_tmp_ip.insert(n2, _tmp_2)
_tmp_ip.insert(n3, _tmp_3)
result.add(tuple(_tmp_ip))
for _ in result:
parsed_result.add('.'.join(_))
return parsed_result '''
socket.inet_aton() 把IPV4地址转化为32位打包的二进制格式 -> 检查是否为ipv4
struct.unpack(fmt,string) 按照给定的格式(fmt)解析字节流string,返回解析出来的tuple
!L: ! = network(=big-endian) L = unsigned long
'''
if __name__ == '__main__':
if len(sys.argv)==2:
ip = sys.argv[1]
ip_int = struct.unpack('!L', socket.inet_aton(ip))[0]
ip_oct_no_comma = oct(ip_int)
ip_hex_no_comma = hex(ip_int)
ip_oct_by_comma = ip_split_by_comma_oct(ip)
ip_hex_by_comma = ip_split_by_comma_hex(ip)
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)
print ip_int
print ip_oct_no_comma
print ip_hex_no_comma
for _ip in all_result:
print _ip
else:
print("Tips: IP.py 127.0.0.1 \n")
爆破解压zip文件:ZIP.py
# -*- coding:utf-8 -*-
import sys
import zipfile
import threading def extractFile(zFile,password):
try:
zFile.extractall(pwd=password.encode("utf-8"))
print("Password is: "+password)
except Exception as e:
print(str(e)) def main():
if len(sys.argv) == 3:
zFile = zipfile.ZipFile(sys.argv[1])
passFile = open(sys.argv[2])
for line in passFile.readlines():
password = line.strip('\n')
t = threading.Thread(target=extractFile,args=(zFile,password))
t.start()
else:
print("Tips:python3 ZIP.py 要爆破的文件 字典") if __name__ =='__main__':
main()
学习和总结
python绝技:运用python成为顶级黑客
一个生成各种进制格式IP的小工具:http://www.freebuf.com/sectool/140982.html
python3 小工具的更多相关文章
- ip地址查询python3小工具_V0.0.1
看到同事在一个一个IP地址的百度来确认导出表格中的ip地址所对应的现实世界的地址是否正确,决定给自己新开一个坑.做一个查询ip“地址”的python小工具,读取Excel表格,在表格中的后续列输出尽可 ...
- Python3 小工具-UDP扫描
from scapy.all import * import optparse import threading def scan(target,port): pkt=IP(dst=target)/U ...
- Python3 小工具-僵尸扫描
僵尸机的条件: 1.足够闲置,不与其他机器进行通讯 2.IPID必须是递增的,不然无法判断端口是否开放 本实验僵尸机选择的是Windows2003 from scapy.all import * im ...
- Python3 小工具-TCP半连接扫描
from scapy.all import * import optparse import threading def scan(ip,port): pkt=IP(dst=ip)/TCP(dport ...
- Python3 小工具-UDP发现
from scapy.all import * import optparse import threading import os def scan(ip): pkt=IP(dst=ip)/UDP( ...
- Python3 小工具-TCP发现
from scapy.all import * import optparse import threading import os def scan(ip): pkt=IP(dst=ip)/TCP( ...
- Python3 小工具-MAC泛洪
from scapy.all import * import optparse def attack(interface): pkt=Ether(src=RandMAC(),dst=RandMAC() ...
- Python3 小工具-ICMP扫描
from scapy.all import * import optparse import threading import os def scan(ipt): pkt=IP(dst=ipt)/IC ...
- Python3 小工具-ARP扫描
from scapy.all import * import optparse import threading import os def scan(ipt): pkt=Ether(dst='ff: ...
随机推荐
- 国内的Android SDK镜像
如果你不愿意改hosts文件,没有好的FQ工具,可以考虑使用国内的镜像源 1.南阳理工学院镜像服务器地址: mirror.nyist.edu.cn 端口:80 2.中国科学院开源协会镜像站地址: IP ...
- 搭建SpringCloud-Eureka 注册中心以及服务提供与调用 快速了解 SpringCloud-Eureka
原文地址: 搭建SpringCloud-Eureka 注册中心以及服务提供与调用 纸上得来终觉浅,绝知此事要躬行啊~果然看着很easy,自己搞起来就是各种坑~各位看官,容我慢慢道来~ 关于spr ...
- IndexDB 操作util
https://dexie.org/ https://www.tangshuang.net/5668.html https://github.com/tangshuang/hello-indexedd ...
- EAS开发报错 :数据库表 或 视图 不存在
一:原因分析 建模之后,发布数据时未能及时在数据库创建相应的表格或视图. 二:解决办法 建模视图下——右键模型——更新数据库. 三:名称字段.描述字段在数据库里的存储格式 ...
- Pilosa文档翻译(一)导言、安装
目录 导言 安装 安装在MacOS 使用HomeBrew 下载二进制文件 从源码构建 使用Docker 安装在Linux 下载二进制文件 从源码构建 使用Docker 接下来是什么? 导言 原文地址 ...
- keil软件错误总结.doc
KEIL编译错误信息表 错误代码及错误信息 错误释义 error 1: Out of memory 内存溢出 error 2: Identifier expected 缺标识符 error 3: ...
- LRU原理和Redis实现——一个今日头条的面试题(转载)
很久前参加过今日头条的面试,遇到一个题,目前半部分是如何实现 LRU,后半部分是 Redis 中如何实现 LRU. 我的第一反应是操作系统课程里学过,应该是内存不够的场景下,淘汰旧内容的策略.LRU ...
- hive SQL 行转列 和 列转行
一.行转列的使用 1.问题 hive如何将 a b 1a b 2a b 3c d 4c d ...
- nrm 安装与npm镜像切换
家里宽带用的移动的...访问海外镜像是相当慢,npm和maven一个道理,maven可以切换到淘宝镜像或者其他的,那么npm也可以使用国内镜像,这个时候就需要用到nrm来做镜像管理了 首先这是目前本地 ...
- Istio究竟是干嘛的?
要聊ServiceMesh,就不得不提Istio,它是ServiceMesh目前最流行的实践, 当微服务架构体系越来越复杂的时候,需要将“业务服务”和“基础设施”解耦,将一个微服务进程一分为二: 一个 ...