首页 > 解决方案 > 使用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)

标签: pythonlinux

解决方案


  1. https://www.w3schools.com/python/ref_string_format.asp
  2. 你不能命名变量 mac-addr
  3. input("输入 MAC 地址\n")

推荐阅读