1 Star 0 Fork 46

北平往事/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.03.03 Scapy ping scan 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-03-03 11:05 . new file
#########################scapy_ping_one##############################
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import re
import time
import sys
from scapy.all import *
def scapy_ping_one(host,i):
idi = int(i)
packet = IP(dst=host, ttl=1, id=idi)/ICMP(id=100,seq=idi)/b'Welcome to qytang'
ping = sr1(packet, verbose = False)
if ping:
os._exit(3)
if __name__ == '__main__':
scapy_ping_one(sys.argv[1],sys.argv[2])
#######################scapy_ping_scan################################
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import re
import time
import multiprocessing
from scapy_ping_one import scapy_ping_one
from scapy.all import *
def scapy_ping_scan(network):
scan_network = re.search('([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/([0-9]+)', network).groups()
#print(scan_network)
processes = []
if scan_network[4] == '24':
for i in range(254):
i = i + 1
ipaddr = scan_network[0]+'.'+scan_network[1]+'.'+scan_network[2]+'.'+str(i)
ping_one = multiprocessing.Process(target=scapy_ping_one, args=(ipaddr, i))
ping_one.start()
processes.append(ping_one)
ip_no = 1
for process in processes:
if process.exitcode == 3:
ok_ip = scan_network[0]+'.'+scan_network[1]+'.'+scan_network[2]+'.'+str(ip_no)
print(ok_ip + ' OK!!!')
else:
process.terminate()
ip_no = ip_no + 1
if __name__ == '__main__':
scapy_ping_scan(sys.argv[1])
###########################测试效果######################################
[root@Fedora python]# ./scapy_ping_scan.py 202.100.1.0/24
202.100.1.100 OK!!!
202.100.1.200 OK!!!
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/jax999/qytang_Python.git
git@gitee.com:jax999/qytang_Python.git
jax999
qytang_Python
qytang_Python
master

搜索帮助