代码拉取完成,页面将自动刷新
======================syn_scan_one_port=====================================
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
import sys
from io import StringIO
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import re
from scapy.all import *
def syn_scan_one_port(hostname,port):
f_handler = StringIO()
__console__=sys.stdout
sys.stdout = f_handler
result_raw = sr(IP(dst=hostname)/TCP(sport=RandShort(),dport=[port],flags="S"), verbose = False)
result_raw[0][0][1].display()
sys.stdout=__console__
scan_raw = f_handler.getvalue()
flag_result = re.findall('.*\s+(flags)\s*=\s*(.*).*', scan_raw)
for flag in flag_result:
if flag[1] == 'SA':
#print('Host: ' + hostname + ' Port:' + str(port) + ' is Open!!!')
os._exit(3)
if __name__ == '__main__':
syn_scan_one_port('202.100.1.200',139)
======================scapy_syn_scan=====================================
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import re
import time
import multiprocessing
from syn_scan_one_port import syn_scan_one_port
from scapy.all import *
def scapy_syn_scan(host,port_low,port_high):
processes = []
ports = []
port_l = int(port_low)
port_h = int(port_high) + 1
for port in range(port_l,port_h):
syn_one = multiprocessing.Process(target=syn_scan_one_port, args=(host, port))
#print('Started ' + str(port) + ' Scan!!!')
syn_one.start()
processes.append(syn_one)
ports.append(port)
#print(processes)
#print(ports)
port_no = 0
time.sleep(3)
for process in processes:
if process.exitcode == 3:
print('Host: ' + host + ' Port:' + str(ports[port_no]) + ' is Open!!!')
else:
process.terminate()
port_no = port_no + 1
if __name__ == '__main__':
host = input('请你输入扫描主机的IP地址: ')
port_low = input('请你输入扫描端口的最低端口号: ')
port_high = input('请你输入扫描端口的最高端口号: ')
scapy_syn_scan(host,port_low,port_high)
#scapy_syn_scan('202.100.1.200',135,140)
=====================扫描效果===================================================
[root@Fedora python]# ./scapy_syn_scan.py
请你输入扫描主机的IP地址: 202.100.1.200
请你输入扫描端口的最低端口号: 100
请你输入扫描端口的最高端口号: 500
Host: 202.100.1.200 Port:135 is Open!!!
Host: 202.100.1.200 Port:139 is Open!!!
Host: 202.100.1.200 Port:445 is Open!!!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。