我正在尝试使用 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/