Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Yet another scripting question

Thread Tools
 
Search this Thread
 
Old 25 November 2008, 04:57 PM
  #1  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
Default Yet another scripting question

Hello All,
Here's another one for you. I want to get the MAC address for device en0 on my machine. I've found two ways so far of doing this:

ifconfig en0 | grep "ether"

Which is returning:

ether 00:16:ed:15:16:2d

and

networksetup -getmacaddress en0

Which is returning:

Ethernet Address: 00:16:ed:15:16:2d (Device: en0)



This is all well and good, however, what I want is just the MAC Address and none of the other text in the string, and I also need to remove the colons as well. So I'd end up with:

0016ed15162d

I'm thinking perhaps grep/sed might be of use here, but I'm not sure exactly what syntax/options/arguments to use.

Could someone point me in the right direction please

Last edited by Markus; 25 November 2008 at 05:01 PM.
Old 25 November 2008, 09:56 PM
  #2  
jpor
Scooby Regular
iTrader: (1)
 
jpor's Avatar
 
Join Date: Sep 2003
Posts: 3,109
Likes: 0
Received 0 Likes on 0 Posts
Default

Can you add the following on at the end of the syntax:

| cut -d:

or if that doesn't work then:

| cut -d ":"


This should remove the ':'

Althiough this works fine in KSH and on AIX. What O/S are you using?

Last edited by jpor; 25 November 2008 at 09:57 PM.
Old 25 November 2008, 10:31 PM
  #3  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
Default

OS X 10.5.5, using bash shell
Old 27 November 2008, 03:47 PM
  #4  
jpor
Scooby Regular
iTrader: (1)
 
jpor's Avatar
 
Join Date: Sep 2003
Posts: 3,109
Likes: 0
Received 0 Likes on 0 Posts
Default

Ahh so LINUX based. Should work the same. Have you tried the following then?

ifconfig en0 | grep "ether" | cut -d":"

The only other way i can think of to get the MAC address in a UNIX way is possibly using the netstat command with the either of the following flags at the end; -ia -in.
Old 27 November 2008, 04:13 PM
  #5  
Hanley
Scooby Regular
 
Hanley's Avatar
 
Join Date: May 2002
Location: Liverpool
Posts: 3,229
Likes: 0
Received 0 Likes on 0 Posts
Default

As you know the beginning of the return is always going to be

Ethernet Address:

Including the space after the colon, can you not use the equivalent to the MID command to take the next 17 characters??

Sorry but I don't know the Linux equivalent to MID

Should be fairly straightforward to remove the colons once you have just the MAC address.


Last edited by Hanley; 27 November 2008 at 04:14 PM.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
slimwiltaz
General Technical
20
09 October 2015 07:40 PM
IanG1983
Wheels, Tyres & Brakes
2
06 October 2015 03:08 PM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM
the shreksta
Other Marques
26
01 October 2015 02:30 PM



Quick Reply: Yet another scripting question



All times are GMT +1. The time now is 10:04 PM.