简体   繁体   中英

Get MAC address of other host on network from Docker container

I'd like to run a program in a container that get's the MAC address from my other host on my local network. I'd like a program running in a container which is bound to a physical interface be treated as a local program, not one running on a remote host.

I have a host that is on a local network. I can get the MAC address from other hosts on my network by using tools like nmap or arp-scan running from that physical host. I would have expected similar behavior when mounting a container to a interface on that same host.

From the physical host I can run, and the results include MAC addresses. If I did the same command using nmap from a remote hosts I'd not get the MAC addresses because it's not able to pull MAC addresses from remote hosts with a -sn scan.

Why is my container being treated as a remote host, which its on a local network?

sudo nmap -sn 192.x.x.x/24 

I've tried mounting my container the following ways

docker run -P -it scanner_container
docker run -P --privileged -it scanner_container
docker run -p 192.x.x.ip-of-interface scanner_container

I have run the following from each of the above

nmap -sn --privileged 192.x.x.x/24
sudo nmap -sn 192.x.x.x/24 

I have also tried arp and arp-scan

I'm not tied to any tool, I'd just like some way to get the MAC addresses on my hosts on my local network from a program that runs inside a container, on a host in my local network.

If nmap is the correct tool to use, then great, otherwise I'm happy to use anything else. I've spent a couple days trying different things and can't seem to bind the container to an interface so that it's treated as the actual host.

I was able to get it to work with the following command. I'm not certain why but this only works on a linux machine and wont work with dockerformac

docker run -it --net=host scanner_container

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM