How to ping MAC address in Linux

后端 未结 5 1510
南方客
南方客 2021-01-31 12:19

I want to ping a known MAC address, I tried to use nmap:

sudo nmap -sP 192.168.15.1/24 | grep  20:64:32:3F:B1:A9

But in this case its ping all

5条回答
  •  忘掉有多难
    2021-01-31 12:57

    The only way to make it faster is to test if the mac address is already into your arp table

    #!/bin/bash
    
    # extract ip from local arp table
    ip=$(arp | grep 20:64:32:3F:B1:A9 | awk ' { print $1 } ')
    
    # found an ip tied to the mac address?
    if [ ! -z $ip ]; then
    
        # if found, do you want to ping it?
        ping $ip
    else
        echo "Not found into local arp table. Trying another way..."
    
        # wanna try your nmap strategy?
        # sudo nmap -sP 192.168.15.1/24 | grep  20:64:32:3F:B1:A9
    fi;
    

提交回复
热议问题