小编Mar*_*tin的帖子

没有root的Python Scapy嗅闻

我想知道是否有可能在没有root权限的情况下运行Scapy的'sniff(...)'.

它用于捕获某些包的应用程序中.但我不想用root权限运行整个应用程序或在scapy itselfe上更改任何内容.

提前致谢!

编辑:

为了测试,我使用以下代码:

from scapy.all import *

def arp_monitor_callback(pkt):
    if ARP in pkt and pkt[ARP].op in (1,2): #who-has or is-at
        return pkt.sprintf("%ARP.hwsrc% %ARP.psrc%")

sniff(prn=arp_monitor_callback, filter="arp", store=0)
Run Code Online (Sandbox Code Playgroud)

我只能用sudo运行它.

我试着设置功能sudo setcap 'cap_net_admin=+eip' test.py.但它没有显示出任何影响.即使是能力all也无济于事.

sniffing scapy python-2.7 linux-capabilities

7
推荐指数
2
解决办法
5571
查看次数

Python抽象方法,它有自己的__init__函数

如何__init__在基本抽象类和派生抽象类中定义函数并self.*在抽象方法中都可用?例如: 

利用在抽象类的基类中导入的函数的正确方法是什么?例如:在base.py中我有以下内容:

import abc

class BasePizza(object):
    __metaclass__  = abc.ABCMeta
    def __init__(self):
        self.firstname = "My Name"

    @abc.abstractmethod
    def get_ingredients(self):
         """Returns the ingredient list."""
Run Code Online (Sandbox Code Playgroud)

然后我在diet.py中定义方法:

import base

class DietPizza(base.BasePizza):
    def __init__(self):
        self.lastname = "Last Name"

    @staticmethod
    def get_ingredients():
        if functions.istrue():
            return True
        else:
            return False
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时,diet.py我只能访问self.lastname.我想要DietPizza两个self.firstnameself.lastname.我怎样才能做到这一点?

python abstract-class abc python-3.x

3
推荐指数
1
解决办法
7653
查看次数