[英]Running an ARP scan on Raspberry Pi with Python
I am trying to run an ARP-scan on my raspberry Pi from a Python script.我正在尝试通过 Python 脚本在我的树莓派上运行 ARP 扫描。
I have tried the following code using the subprocess library, however when I attempt to print output I receive the error that there is no such variable我已经使用 subprocess 库尝试了以下代码,但是当我尝试打印输出时,我收到没有这样的变量的错误
p = subprocess.Popen(" sudo arp-scan -l", stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
status = p.wait()
print(output)
print(err)
Is anyone able to tell me what I am doing wrong?有人能告诉我我做错了什么吗?
Many thanks in advance提前谢谢了
Try like this:试试这样:
import subprocess
p = subprocess.run("sudo /usr/sbin/arp-scan -l", shell=True, capture_output=True)
print(p.stdout)
I have been a bit stupid.我已经有点傻了。 I was testing these commands on a Python terminal on my pi and it would not print output.
我在我的 pi 上的 Python 终端上测试这些命令,但它不会打印输出。 However when I save this as a script and execute it, it works as it should.
但是,当我将其保存为脚本并执行它时,它可以正常工作。 Thanks for the help
谢谢您的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.