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: ...
随机推荐
- pygame-KidsCanCode系列jumpy-part16-enemy敌人
接上回继续,这次我们要给游戏加点难度,增加几个随机出现的敌人,玩家碰到敌人后Game Over. 最终效果如下,头上顶个"电风扇"的家伙,就是敌人. 一.先定义敌人类 # 敌人类 ...
- Linux进程管理学习资料
下面是一些Linux进程管理相关的资料. 博客 Process Creation(一) Process Creation(二) 进程切换分析(1):基本框架 进程切换分析(2):TLB处理 When ...
- Asp.Net Core IIS发布后PUT、DELETE请求错误405.0 - Method Not Allowed 因为使用了无效方法(HTTP 谓词)
一.在使用Asp.net WebAPI 或Asp.Net Core WebAPI 时 ,如果使用了Delete请求谓词,本地生产环境正常,线上发布环境报错. 服务器返回405,请求谓词无效. 二.问题 ...
- python接口自动化测试(四)-Cookie&Sessinon
掌握了前面几节的的内容,就可以做一些简单的http协议接口的请求发送了,但是这些还不够.HTTP协议是一个无状态的应用层协议,也就是说前后两次请求是没有任何关系的,那如果我们测试的接口之前有相互依赖关 ...
- Linux远程执行shell命令
Linux远程执行shell命令 在Linux系统中,我们经常想在A机器上,执行B机器上的SHELL命令. 下面这种方案,是一种流行可靠的方案. 1.SSH无密码登录 # 本地服务器执行(A机器) ...
- 试水STF(smartphone test farm)
STF简介 简介: STF , smartphone test farm, 是一款能够通过浏览器远程管理智能设备的系统, 能为移动自动化测试提供方便快捷的服务,免去测试工程师的后顾之忧. 功能点: 支 ...
- IoC之AutoFac(三)——生命周期
阅读目录 一.Autofac中的生命周期相关概念 二.创建一个新的生命周期范围 三.实例周期范围 3.1 每个依赖一个实例(InstancePerDependency) 3.2 单个实例(Sin ...
- 关于XCode工程中PrefixHead.pch文件的使用
1.首先先清除pch文件在工程中的作用: 存放一些全局的宏(整个项目中都用得上的宏) 用来包含一些全部的头文件(整个项目中都用得上的头文件) 能自动打开或者关闭日志输出功能 2.由于新建的XCode工 ...
- Atitit.如何文章写好 论文 文章 如何写好论文 技术博客
Atitit.如何文章写好 论文 文章 如何写好论文 技术博客 1. 原则 1 1.1. 有深度, 有广度 1 1.2. 业务通用性有通用性 尽可能向上抽象一俩层..业务通用性与语言通用性. 2 ...
- Python实现im2col和col2im函数
今天来说说im2col和col2im函数,这是MATLAB中两个内置函数,经常用于数字图像处理中.其中im2col函数在<MATLAB中的im2col函数>一文中已经进行了简单的介绍. 一 ...