weixin_43591208 2019-11-21 10:20 采纳率: 0%
浏览 811

python使用scapy,使用发包工具时,报错NameError: name 'udp' is not defined,求解答,

#!env python
# -*- coding: <encoding name> -*-
import sys
from scapy.all import *
import os,random,datetime,time,math
from random import randrange
from random import uniform
from functools import reduce


def create_data(line):
    current_time = [
    datetime.datetime.now().strftime('%b %d %H:%M:%S'),
    datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
    # datetime.datetime.now().strftime('%b %d %H:%M:%S %Y'),
    str(math.trunc(datetime.datetime.now().timestamp()))
]

regular = [
    "(\w{3}\s+\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2})",
    "(\d{4}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2})",
    "(\w{3}\s+\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2}\s+\d{1,4})",
    "(\d{10})"
]

def current_time(line):
    for i in regular:
        for j in current_time(line):
            if len(re.findall(i, j)) != 0:  #若正则匹配上相对应的时间格式,则对字符串进行替换
               line=re.sub(i,j,line)
            return line


dict_ip_logfile={
        "192.168.58.84":  r"C:\Users\CS\Desktop\HPHIDS.txt"
        }
while True:
    for ip,logfile in dict_ip_logfile.items():
        with open(logfile,"r",encoding='unicode_escape') as log:
            for line in log:
                print(ip)
                print(logfile)
                print(create_data(line))
                # IP = (porto='udp','192.168.57.45')
                # UDP = (dst='192.168.57.14',8089)
                # scapy.all,send(IP,udp)
                scapy.all.send(IP(proto="udp",src=ip,dst="192.168.57.45")/udp(dst='192.168.57.14.',dport=8082)/line,inter=5,loop=1,count=2)
        log.close()

图片说明

  • 写回答

1条回答 默认 最新

  • CounterGlew511 2022-12-26 18:10
    关注

    /后面的UDP大写

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题