Is it possible to somehow display the MAC addresses of all network interfaces for systems that have an IP address in the subnets of the source system (that is, the one on which the script is running)? Using ssh or rsh .

How to get the subnet I found on the Internet:

 subnets=(` ifconfig -a | grep broadcast | gawk '{print $2}'`) 

I thought to use the ifconfig command, but on the network they write the following:

The results of the ifconfig -а command will vary depending on who calls it: the root user or a row user. This applies to both versions of the command. In the first case, besides IP addresses and parameters, MAC addresses are also displayed.

I need the script to be launched on behalf of a regular user, and not just from the root. And how to combine all this into a single script? I need for OS Solaris . Will there be differences in the work, for example, from running on Ubuntu ?

    4 answers 4

    Well, first try (it works in both unix and windows)

     arp -a 

    Get the MAC addresses from the ARP table. It is constantly updated, over time you can accumulate information (no need to wait long, by the way, new entries will appear in the table, for example, after ping some node that was not previously listed).

    You can still like this

     netstat -rn 

    (but it will work only in unix-ah, and preferably run on a router).

       arp-scan -l 

      You can set up an interface like this

       arp-scan -l -I eth0 

      This is how it displays:

       192.168.xx.x 00:19:2f:xx:xx:xx Cisco Systems192.168.xx.x 00:50:22:xx:xx:xx ZONET TECHNOLOGY, INC.192.168.xx.x 00:1f:c6:xx:xx:xx ASUSTek COMPUTER INC. 

        The algorithm is as follows:

        1. we get the address of the broadcast IP on the source server:

          ifconfig -a

        2. After the word broadcast, there is a broadcast IP. Making it:

          ping -s broadcast_ip

          To stop the output, use the Ctrl-C combination or specify the size and number of packets at the end of the command, separated by spaces.

        3. We will answer a lot of machines in the subnet (for whom ICMP is not closed). After that, the machine's ARP table will be filled. It will be enough to view it:

          arp -a

        As you can see, it is enough to login a regular user to the machine on the network. No access to the router and root rights.

          nmap 192.168.1.0/29 | grep -P 'report | MAC'