我试图比较嗅探包。我必须将src
地址与之前的地址进行比较,并将dst
地址与#!/usr/bin/evn python
from scapy.all import *
pkt = sniff(filter="ip",timeout=5)
for p in pkt:
try:
if IP in pkt:
ip_src=pkt[IP].src
ip_dst=pkt[IP].dst
if (pkt[IP].src[p]!=pkt[IP].src[p+1])
packet=pkt[IP].src
return packet
print "packets not equal"
地址进行比较。
到目前为止,这是我的代码:
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
startindex= matcher.start();
stopindex=matcher.end();
// Your code for replacing that index and generating a new string with foo
// you can use string buffer to delete and insert the characters as you know the indexes
}
}
但这似乎并不合适。任何人都可以帮助我吗?
答案 0 :(得分:0)
所以这里有一些问题,主要是你的Python语法。
1)" if" python中的语句如下所示:
if 1 == 1:
print "Hello World!"
2)请注意,在使用print
后尝试使用return
命令。这不起作用,因为一旦你使用return函数将完成运行。例如:
def test():
return "Hello world" #Will run and exit the function
print "Hello wolrd2!" #Will not run since the function was finished on the line above
解决了这些问题后,我建议您查看代码并将其修复为正确的Python语法。