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: ...
随机推荐
- git 一些常见问题 总结
问题1: Auto packing the repository in background for optimum performance. See "git help gc" ...
- delphi TTBXToolBar 增加外部控件
这样可以引用外部控件,还是比较方便
- Win10注册表无法保存对权限所作的更改拒绝访问
在对系统的安全控制得越来越多的情况下,要对注册表的关键数据进行修改是件挺麻烦的事,时不时会弹出无法保存对xxxxxx权限所作的更改,拒绝访问,操作产生错误,操作出现错误的提示,这时怎么办呢?这里就最近 ...
- CSS魔法堂:改变单选框颜色就这么吹毛求疵!
前言 是否曾经被业务提出"能改改这个单选框的颜色吧!让它和主题颜色搭配一下吧!",然后苦于原生不支持换颜色,最后被迫自己手撸一个凑合使用.若抛开input[type=radio] ...
- 超过 130 个你需要了解的 vim 命令
从 1970 年开始,vi 和 vim 就成为了程序员最喜爱的文本编辑器之一.5年前,我写了一个问自己名为 “每个程序员都应该知道的 100 个 vim 命令” 这次算是之前那篇文章的改进版,希望你会 ...
- grid - 隐式命名网格线名称
1.隐式的指定网格线反向指定了隐式的网格区域名称,命名的网格区域隐式的命名了网格线名称. 指定网格区域会给网格区域边线添加隐式的网格线名称.这些网格线的命名是基于网格区域来命名,只是在网格区域名称的后 ...
- PHP 实现自动加载
自动载入主要是省去了一个个类去 include 的繁琐,在 new 时动态的去检查并 include 相应的 class 文件. 先上代码: //index.php <?php class Cl ...
- sqlbulkcopy 多表批量保存
/// <summary> /// 批量保存多表 /// </summary> /// <param name="dt1"></param ...
- CAP二十年:“规则”变了
本文是原文https://www.cnblogs.com/cobbliu/p/7494961.html的译文,原链接:http://www.infoq.com/cn/articles/cap-twel ...
- AYUI第12个作品-英雄联盟-魔法少女的星光水晶2.0-WPF版本
一下 内容基于AYUI6.7制作,主要3个大控件,1个 轮播预览,一个抽奖展示,一个是自己的抽中的历史展示,还有礼品领取,图片变成黑白的滤镜,滚动条网页方式布局 历时4天,制作效果如下: 由于自己爬了 ...