与Python在Raspberry Pi上进行ARP扫描

发布于 2025-02-03 05:11:11 字数 301 浏览 2 评论 0原文

我试图通过Python脚本在Raspberry Pi上运行ARP扫描。

我已经使用了子过程库尝试了以下代码,但是当我尝试打印输出时,我收到的错误是没有

p = subprocess.Popen(" sudo arp-scan -l", stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
status = p.wait()

print(output)
print(err)

人能够告诉我我在做什么错?

非常感谢

I am trying to run an ARP-scan on my raspberry Pi from a Python script.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

惯饮孤独 2025-02-10 05:11:11

这样尝试:

import subprocess

p = subprocess.run("sudo /usr/sbin/arp-scan -l", shell=True, capture_output=True)
print(p.stdout)

Try like this:

import subprocess

p = subprocess.run("sudo /usr/sbin/arp-scan -l", shell=True, capture_output=True)
print(p.stdout)
○愚か者の日 2025-02-10 05:11:11

我有点愚蠢。我在PI上的Python终端上测试了这些命令,它不会打印输出。但是,当我将其保存为脚本并执行它时,它会尽可能地工作。
感谢您的帮助

I have been a bit stupid. I was testing these commands on a Python terminal on my pi and it would not print output. However when I save this as a script and execute it, it works as it should.
Thanks for the help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文