python - 使用python通过linux命令运行输入
问题描述
我是 python 网络的新手。我需要运行 Linux 命令来捕获流量,但我需要输入 mac 地址。
我尝试过使用 python 来做到这一点,但我不知道如何将 value get 从用户导入到我的命令
#!/usr/bin/python
import os
mac-addr = input("Enter MAC-address"\n)
cmd = 'tcpdump -ni eth1 ether **<MAC-address need to be here>** -c 100 -w /opt/mirror-traffic/mirror_$(%A-%B-%d-%Y_%H-%M-%S).pcap'
output = os.system(cmd)
解决方案
- https://www.w3schools.com/python/ref_string_format.asp
- 你不能命名变量 mac-addr
- input("输入 MAC 地址\n")
推荐阅读
- java - 如何在 Java 中跳过 Regex 的某些部分?
- javascript - 如何按随机整数/变量(onclick)进行计数?
- c# - Identity Server 4 OpenID Connect Discovery 是否应该公开?
- python - quickfix python 如何使用 SSLSocketInitiator?
- cypress - 如何使用 Cypress.io 将 baseUrl 作为参数发送
- typescript - 在打字稿中获取字典/对象键作为元组
- java - MediaPlayerService 销毁后传输控件不更新
- html - 标签和标签之间的CSS区别
- javascript - Eslint 的正确 YAML - 值不应超过 1 个项目 - 无多空行
- r - 频率变化不规则时间序列