[英]How to fetch MAC address of remote machine from docker container
I am using python:3.6-alpine
docker container. 我正在使用
python:3.6-alpine
docker容器。
I have a network service which finds MAC address of a supplied ip address. 我有一个网络服务,可以找到提供的IP地址的MAC地址。 To find mac address of given remote machine say
host=10.11.15.100
i'm using below python3 script. 要查找给定远程计算机的mac地址,请说
host=10.11.15.100
我正在使用以下python3脚本。
import getmac
mac_address = getmac.get_mac_address(ip=host)
When I run this script locally it gives proper mac address of provided host. 当我在本地运行此脚本时,它将提供所提供主机的正确mac地址。 But when I run it in docker container it gives
None
. 但是当我在docker容器中运行它时,它给出
None
。
Note:- I am able to ping given host from docker container but unable to get mac address. 注意:-我能够从docker容器ping通给定的主机,但无法获取mac地址。
使用此命令获取容器的MacAddress
docker container inspect -f {{.NetworkSettings.MacAddress}} container-id
If you are able to ping given remote machine from docker container but unable to get the mac address that means either 如果您能够从Docker容器ping通给定的远程计算机,但无法获取mac地址,则意味着
For #1 case you can ping the machine which can add MAC address of that machine in the routing table. 对于#1情况,您可以ping通该计算机,该计算机可以在路由表中添加该计算机的MAC地址。
For #2 case you can add a host network interface to Docker container. 对于#2情况,您可以将主机网络接口添加到Docker容器。
eg. 例如。
docker run --network="host" -it network_service:latest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.