LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 05-17-2006, 08:42 AM   #1
sadafwaqas
LQ Newbie
 
Registered: May 2006
Posts: 4

Rep: Reputation: 0
mac address of local machine


How to know MAC address of the ethernet card of my local machine programmetically??
 
Old 05-17-2006, 09:37 AM   #2
winxandlinx
Member
 
Registered: May 2006
Posts: 141

Rep: Reputation: 15
Hi sadafwaqas ,

I mean do you need command to check the mac address ?
 
Old 05-17-2006, 09:56 AM   #3
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 383

Rep: Reputation: 31
OK...let's do this from a standard shell. First, let's see what the output for eht0 is using ifconfig:

Code:
jka@puppy:/proc$ /sbin/ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:12:3F:A7:4C:37
          inet addr:10.227.89.198  Bcast:10.227.89.255  Mask:255.255.255.0
          inet6 addr: fe80::212:3fff:fea7:4c37/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:32352780 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8937727 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1477472548 (1.3 GiB)  TX bytes:1164971246 (1.0 GiB)
          Interrupt:169
Well...looks like we have the MAC address right there on the first line, so let's grep that out:

Code:
jka@puppy:/proc$ /sbin/ifconfig eth0 | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 00:12:3F:A7:4C:37
OK, we have the line, which is nice, but there is a bunch of junk there, so let's get rid of that:

Code:
jka@puppy:/proc$ /sbin/ifconfig eth0 | grep HWaddr | awk '{print $5}'
00:12:3F:A7:4C:37
But, what if we need to put that into something like a dhcpd.conf file? Those upper-case characters just aren't going to fly in there (no, really, they aren't.):

Code:
jka@puppy:/proc$ /sbin/ifconfig eth0 | grep HWaddr | awk '{print $5}' | tr "[A-F]" "[a-f]"
00:12:3f:a7:4c:37
And, if those pesky colons in there are annoying you and you need just a stream of letters and numbers:

Code:
jka@puppy:/proc$ /sbin/ifconfig eth0 | grep HWaddr | awk '{print $5}' | tr "[A-F]" "[a-f]" | tr -d "[:]"
00123fa74c37
 
Old 05-19-2006, 05:39 AM   #4
pronoy
Member
 
Registered: Mar 2005
Location: india
Distribution: FC4, Debian Etch
Posts: 67

Rep: Reputation: 15
you can parse it from 'ip addr show dev eth0' also
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find an IP address from the MAC address of a remote machine ? jitz Linux - General 3 01-03-2006 08:55 AM
How to find IP address of a machine if I know their MAC Address dysenteryduke Linux - Networking 13 09-12-2005 11:21 AM
how to get ip address of local machine using linux commands shahidawan Linux - General 1 03-31-2005 06:26 AM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 05:33 AM
How to know MAC address ( Machine address)?? vanhelsing Linux - Networking 3 08-12-2004 10:30 AM


All times are GMT -5. The time now is 07:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration