扫描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 小工具的更多相关文章

  1. ip地址查询python3小工具_V0.0.1

    看到同事在一个一个IP地址的百度来确认导出表格中的ip地址所对应的现实世界的地址是否正确,决定给自己新开一个坑.做一个查询ip“地址”的python小工具,读取Excel表格,在表格中的后续列输出尽可 ...

  2. Python3 小工具-UDP扫描

    from scapy.all import * import optparse import threading def scan(target,port): pkt=IP(dst=target)/U ...

  3. Python3 小工具-僵尸扫描

    僵尸机的条件: 1.足够闲置,不与其他机器进行通讯 2.IPID必须是递增的,不然无法判断端口是否开放 本实验僵尸机选择的是Windows2003 from scapy.all import * im ...

  4. Python3 小工具-TCP半连接扫描

    from scapy.all import * import optparse import threading def scan(ip,port): pkt=IP(dst=ip)/TCP(dport ...

  5. Python3 小工具-UDP发现

    from scapy.all import * import optparse import threading import os def scan(ip): pkt=IP(dst=ip)/UDP( ...

  6. Python3 小工具-TCP发现

    from scapy.all import * import optparse import threading import os def scan(ip): pkt=IP(dst=ip)/TCP( ...

  7. Python3 小工具-MAC泛洪

    from scapy.all import * import optparse def attack(interface): pkt=Ether(src=RandMAC(),dst=RandMAC() ...

  8. Python3 小工具-ICMP扫描

    from scapy.all import * import optparse import threading import os def scan(ipt): pkt=IP(dst=ipt)/IC ...

  9. Python3 小工具-ARP扫描

    from scapy.all import * import optparse import threading import os def scan(ipt): pkt=Ether(dst='ff: ...

随机推荐

  1. Git 和 Repo常用命令

    这篇博客总结的也不错: git常用及进阶命令总结 Git与Repo入门 一.初始環境配置 git config --global user.name "John Doe"git c ...

  2. EBS WebADI 存储过程增加参数

    CREATE OR REPLACE FUNCTION CUX_EXEC_SQL (P_SQL IN VARCHAR2)   RETURN NUMBERAS   L_CNT   NUMBER;BEGIN ...

  3. window Form中使用Font Awesome z

    图标字体是矢量的,矢量图意味着每个图标都能在所有大小的屏幕上完美呈现,可以随时更改大小和颜色,而且不失真,真心给人一种“高大上”的感觉.由于Font Awesome是完全免费的,无论个人还是商业使用, ...

  4. 微信公众号申请+新浪SAE申请

    一. 新浪SAE服务申请 1. 注冊地址:http://t.cn/RqMHPto 2. 选择控制台>>云应用SAE 3. 创建新应用 4. 填写域名 5. 代码管理选择SVN 6. 创建版 ...

  5. 您的第一个C++Builder程序(Hello, world!)

    最近有些老旧的项目是C++Builder开发的,虽然和Delphi的IDE的界面和操作十分相似,但是还是找本<C++ Builder 5 Developer's Guide>来看看熟悉下, ...

  6. [开源]开放域实体抽取泛用工具 NetCore2.1

    开放域实体抽取泛用工具 https://github.com/magicdict/FDDC 更新时间 2018年7月16日 By 带着兔子去旅行 开发这个工具的起源是天池大数据竞赛,FDDC2018金 ...

  7. Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test java.lang.IllegalStateException

    不能找到对应的带有@SpringBootConfiguration 的类,你需要将它放在包的最顶层.

  8. C++ 字面量

    https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp?view=vs-2017 C++ supports ...

  9. RSEG用法和汇编问号的涵义

    RSEG是段选择指令,要想明白它的意思就要了解段的意思.段是程序代码或数据对象的存储单位.程序代码放到代码段,数据对象放到数据段.段分两种,一是绝对段,一是再定位段.绝对段在汇编语言中指定,在用L51 ...

  10. CentOS 6.5 x64下查看服务版本

    1.查看服务是否是64位 [root@Yimmei ~]# getconf LONG_BIT 642.查看服务器版本信息 [root@Yimmei ~]# lsb_release -a LSB Ver ...