Skip to content

Fails to sniff packages when starting in systemd service, until systemctl restart #4885

@sezanzeb

Description

@sezanzeb

Brief description

My systemd service looks something like this

[Unit]
Description=asdf

[Service]
Type=simple
ExecStart=/usr/bin/python3 -u /usr/bin/foo
Restart=on-failure

[Install]
WantedBy=graphical.target

and my usage of sniff boils down to

from scapy.sendrecv import sniff
import time
while True:
    packages = sniff(
        filter="udp portrange 2000-3000",
        timeout=2,
    )
    print(packages)
    time.sleep(10)

As far as I know WantedBy=graphical.target is the latest point at which I can start the service, still, it does not detect any traffic later when I interact with my system.

I was hoping that there is a way to make scapy reset or check for changes in network interfaces or whatever to make it work, but couldn't find anything.

As soon as I do systemctl restart asdf.service it starts detecting traffic

Adding a minute of sleep via bash -c "sleep 60 && ... also makes it work.

Scapy version

2.6.1+dfsg-1

Python version

3.13.3

Operating system

6.14.0-37-generic, Ubuntu 25.04

Additional environment information

No response

How to reproduce

see above

Actual result

doesn't capture any network traffic

Expected result

captures network traffic

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions