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: ...
随机推荐
- openjdk for window
https://developers.redhat.com/products/openjdk/download/ https://github.com/dmlloyd/openjdk
- 演练:调试 Windows 窗体
Windows 窗体是最常见的托管应用程序之一. Windows 窗体创建标准的 Windows 应用程序. 你可以完成此演练使用 Visual Basic 中, C#,或 c + +. 首先,您必须 ...
- 00、Word Count
1.开发环境 1.eclipse-jee-neon-3 2.scala-ide:http://download.scala-ide.org/sdk/lithium/e46/scala212/stabl ...
- 通过chrome console 快速获取网页连接
通过chrome console 快速获取网页连接 var ip = document.getElementsByClassName("jDesc"); var str = &qu ...
- 连接postgres特别消耗cpu资源而引发的PostgreSQL性能优化考虑
由于是开发阶段,所以并没有配置postgres的参数,都是使用安装时的默认配置,以前运行也不见得有什么不正常,可是前几天我的cpu资源占用突然升高.查看进程,发现有一个postgres的进程占用CPU ...
- mybatis插入一个对象后获取表中自增的主键Id并且传入到插入的的对象中,方便将对象中其他属性赋值给其他以前表主键Id作为非空字段的表
原本的sql语句为: <insert id="xx" parameterType="com.hrt.partner.model.ShopInsert"&g ...
- 51单片机stack堆栈
一般编译器的堆栈用于保存局部变量.函数的参数.函数的返回值.中断上下文信息等.但Keil对局部变量.函数参数预先分配空间(放在静态全局变量区),Keil的堆栈只是用于保存函数嵌套调用的PC.中断上下文 ...
- 【C#】解析C#中LING的使用
LING提供了一种从数据源中获取数据的方式,不同的语言已经形成了很多种关联的数据源.LING(Language Integrated Query,语言集成查询)提供一种通用的从不同的数据源中获取数据的 ...
- 超简单的okHttpUtils封装(下)
版权声明:转载请注明出处:http://blog.csdn.net/piaomiao8179 https://blog.csdn.net/piaomiao8179/article/details/ ...
- WebSocket 理论知识整理
最近工作用到websocket, 之前虽然也用到了一些简单的东西,但是并没有认真整理一下.所以这次准备了解一下WebSocket. WebSocket产生的背景 WebSocket是一种在单个TCP连 ...