Get MAC address without root

Home -> UNIX -> Solaris -> Network administration

34940 views

From the computer of: rotten (1 recipe)
Created: Dec 02, 2004


2 comments:
View all comments

Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

Of course you can grab the MAC addresses for your interfaces with "ifconfig -a" as root on Solaris 8. However if you want to get them as a regular user use arp.

Here is a script to do it for you:

#!/bin/ksh

# Quick script by rotten to report the MAC addresses on the server.

PATH=$PATH:/usr/sbin; export PATH

hostname=`hostname`

# We are only interested in devices that are configured on boot.

for nic in `ls /etc/hostname.*`
do

# Get the device name.
nicbit=`echo $nic | cut -d. -f2`

# This doesn't work very well on IPMP hosts where there is all sorts
# of extra garbage in the hostname file:
#nichost=`cat /etc/hostname.$nicbit`

# So instead we glean the IP address for the interface from ifconfig:
nicip=`ifconfig $nicbit | grep inet | awk '{ print $2 }'`

# Then we grab the first hostname from /etc/hosts with that IP address.
# It had better be in /etc/hosts - local interfaces are usually there and
# not stashed off box in a name service...
nichost=`grep $nicip /etc/hosts | grep -v "^#" | head -1 | awk '{ print $2 }'`

# There seems to be the occaisional case where the IP is not in /etc/hosts,
# but set directly in /etc/hostname.xxx.
# In this case the arp table probably lists the interface by IP rather than
# hostname.
if [[ -z $nichost ]]
then
nichost=$nicip
fi


# This line is just to see if we are doing ok so far.
#printf "DEBUG --> nicbit=%s\tnicip=%s\tnichost=%s\n" $nicbit $nicip $nichost

# Now we snag the MAC address from the arp table.
macbit=`arp -a | grep $nichost | head -1 | awk '{ print $5 }'`

# And neatly format the results. The "...." are so that the columns line up
# without too much white space.
printf "%s\t%s\t.... %s \n" $hostname $nicbit $macbit

done

# Isn't Solaris fun?

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.




2 Recipe comments: View comments

Get MAC address without root by Anonymous
Re: Get MAC address without root by VeyronMick



Related recipes:

  Change the subnet mask of an interface
  Configure interface automatically with DHCP
  Simple Solaris IP Multipathing
  Solaris 10: set subnet mask in zone
  Create a virtual interface in Solaris
  Remove a virtual interface in Solaris
  Setting Solaris Network Tunable Parameters
  Check hme ethernet link speed, duplex, and status in Solaris
  Add a default route
  View the routing table in Solaris

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.