我有一个原始套接字python程序。它手动运行,但是当我安排它通过cron重启时运行时,它不会启动。 这是代码:
import socket
BUF_SIZE = 65535
ETH_P_ALL = 3
Interface = "eth0"
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_ALL))
sock.bind((Interface, ETH_P_ALL))
sock.setblocking(0)
while True:
try:
packet = sock.recv(BUF_SIZE)
except socket.error:
pass
else:
file = open("/home/user/Log.txt","a")
file.write(packet)
Iam发送数据但它没有将其写入文件。我必须在每次启动后手动运行它以捕获数据包。无法通过cron在启动时运行它。
这里是crontab内容:
@reboot python /home/user/receiver.py