使用scapy制作udp扫描器时始终返回None

新手上路,请多包涵

初学python,之前在Freebuf上找到了一个UDP端口扫描的代码:

#! /usr/bin/python

import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *

dst_ip = "10.0.0.1"
src_port = RandShort()
dst_port=53
dst_timeout=10

def udp_scan(dst_ip,dst_port,dst_timeout):
    udp_scan_resp = sr1(IP(dst=dst_ip)/UDP(dport=dst_port),timeout=dst_timeout)
    if (str(type(udp_scan_resp))==""):
        retrans = []
        for count in range(0,3):
            retrans.append(sr1(IP(dst=dst_ip)/UDP(dport=dst_port),timeout=dst_timeout))
        for item in retrans:
            if (str(type(item))!=""):
                udp_scan(dst_ip,dst_port,dst_timeout)
        return "Open|Filtered"
    elif (udp_scan_resp.haslayer(UDP)):
        return "Open"
    elif(udp_scan_resp.haslayer(ICMP)):
        if(int(udp_scan_resp.getlayer(ICMP).type)==3 and int(udp_scan_resp.getlayer(ICMP).code)==3):
            return "Closed"
        elif(int(udp_scan_resp.getlayer(ICMP).type)==3 and int(udp_scan_resp.getlayer(ICMP).code) in [1,2,9,10,13]):
            return "Filtered"

print udp_scan(dst_ip,dst_port,dst_timeout)

这段代码在实际测试时发现一直在循环扫描,发现udp_scan_resp中的值始终都是udp(不管目标机器的udp端口是否开放,这个变量存储的返回值始终都是None),在网上找了很多udp端口扫描的脚本都是一样都在这里返回了none,来请问各位这里到底应该怎么使用?

阅读 5.4k
2 个回答
新手上路,请多包涵

明白了,我是在BT5虚机对实机进行测试的,网卡是同一块,测试其他机器就没问题了

一直在循环扫描 vs. 发现udp_scan_resp中的值始终都是udp
这2个怎么可能同时出现,一直在循环扫描,肯定是这个条件成立了啊,if (str(type(udp_scan_resp))==""):

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题