<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Get_mac</id>
	<title>Get mac - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Get_mac"/>
	<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Get_mac&amp;action=history"/>
	<updated>2026-04-13T00:31:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.scott5.org/index.php?title=Get_mac&amp;diff=476&amp;oldid=prev</id>
		<title>Scott at 19:47, 4 February 2011</title>
		<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Get_mac&amp;diff=476&amp;oldid=prev"/>
		<updated>2011-02-04T19:47:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{lowercase title}}&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get MAC address for input IP address&lt;br /&gt;
# or exit if not on network&lt;br /&gt;
&lt;br /&gt;
default_subnet=&amp;quot;123.45.67&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function usage {&lt;br /&gt;
    echo &amp;quot;Usage: $0 &amp;lt;ip-address&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
# parse inputs&lt;br /&gt;
if (( $# &amp;lt; 1 )); then&lt;br /&gt;
    echo &amp;quot;Error: Not enough arguments&amp;quot;&lt;br /&gt;
    usage&lt;br /&gt;
    exit 1;&lt;br /&gt;
fi&lt;br /&gt;
ip=$1&lt;br /&gt;
# if input IP is just a single number, append it to default subnet&lt;br /&gt;
ip_period=`echo $ip | grep &amp;quot;\.&amp;quot;`&lt;br /&gt;
#echo &amp;quot;ip_period is $ip_period&amp;quot;&lt;br /&gt;
if [[ $ip_period == &amp;quot;&amp;quot; ]]; then&lt;br /&gt;
    ip=${default_subnet}.$ip&lt;br /&gt;
fi&lt;br /&gt;
#echo &amp;quot;IP address is $ip&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ping_string=`ping -c 1 $ip | grep icmp_seq`&lt;br /&gt;
#echo &amp;quot;ping string is $ping_string&amp;quot;&lt;br /&gt;
unreachable_string=`echo $ping_string | grep Unreachable`&lt;br /&gt;
unreachable=${#unreachable_string}&lt;br /&gt;
#echo &amp;quot;unreachable is $unreachable&amp;quot;&lt;br /&gt;
if (( &amp;quot;$unreachable&amp;quot; &amp;lt;= 0 )); then&lt;br /&gt;
    mac=`/usr/sbin/arp -a $ip | awk &amp;#039;{print $4}&amp;#039;`&lt;br /&gt;
    #echo &amp;quot;mac is $mac&amp;quot;&lt;br /&gt;
    if [[ &amp;quot;$mac&amp;quot; == &amp;quot;entries&amp;quot; ]]; then&lt;br /&gt;
	thisip=`/sbin/ifconfig eth0 | grep &amp;quot;inet addr:&amp;quot; | awk &amp;#039;{print $2}&amp;#039; | awk -F: &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
	#echo &amp;quot;thisip is $thisip&amp;quot;&lt;br /&gt;
	if [[ &amp;quot;$ip&amp;quot; == &amp;quot;$thisip&amp;quot; ]]; then&lt;br /&gt;
	    mac=`/sbin/ifconfig eth0 | grep HWaddr | awk &amp;#039;{print $5}&amp;#039;`&lt;br /&gt;
	    echo $mac&lt;br /&gt;
	fi&lt;br /&gt;
    else&lt;br /&gt;
	echo $mac&lt;br /&gt;
    fi&lt;br /&gt;
fi&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Scott</name></author>
	</entry>
</feed>