Yet another scripting question
#1
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
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
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.
#2
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?
| 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.
#4
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.
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.
#5
Scooby Regular
Join Date: May 2002
Location: Liverpool
Posts: 3,229
Likes: 0
Received 0 Likes
on
0 Posts
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.
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.
Thread
Thread Starter
Forum
Replies
Last Post
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM