python - 使用 Scapy 编写脚本

标签 python linux unicode scapy

我正在尝试使用 Scapy(数据包操作工具)编写一个脚本,该脚本将使用以下代码更改数据包:

def sendCommand(self):
    src = self.srcAdd.toPlainText()
    dst = self.destAdd.toPlainText() #getting strings from textedits
    pay = self.payload.toPlainText()
    print(src + dst + pay) #testing line
    command = IP(dst=dst, src=src)/ICMP()/pay #line giving error

我使用了额外的变量来进行测试,例如“csrc”和“cpay”

所有标记为#testing 的行都正常工作

这是我得到的错误

Traceback (most recent call last):
File "MainDriverScapy.py", line 30, in createCommand
command = IP(dst=dst,src=src)/ICMP()/pay
File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 271, in __div__
return other.__rdiv__(self)
AttributeError: 'unicode' object has no attribute '__rdiv__'

它似乎没有将变量插入到 Scapy 命令的给定字段中。

最佳答案

弄清楚了,结果是 toPlainText 方法以 scapy 无法理解的不寻常编码留下了文本,所以我使用 str() 方法将它转换为字符串。

c = str(self.srcAdd.toPlainText())
dst = str(self.destAdd.toPlainText()) #getting strings from textedits
pay = str(self.payload.toPlainText())

关于python - 使用 Scapy 编写脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41985118/

相关文章:

python - 字节命令功能不适用于 PySerial

java - 从 Java 中的阿拉伯 Unicode 代码点列表中检索表示形式的任何方法

由于 unicode 问题,Python 无法导出到 Stata?

unicode - 使用 unicode 输入显示 "input too long"错误的最佳方法?

python - 如何在列中拆分类型为 dict 的 pandas 列?

python - 模块未找到错误 : No module named 'flask_session'

linux - 脚本的聚合输出

c++ - 原始套接字接收 1504 个字节 (MTU = 1500)

linux - BASH 后台进程打印消失提示行

python - Django 通过多个过滤多对多