![]() |
applescript to just get the ethernet address fom en0
I've been working on an applescript to just get the ethernet address from ethernet 1 (en0) and put it on the clipboard. Here's what I've got so far:
tell application "Terminal" do script with command "ifconfig en0 ether | pbcopy" tell window 1 set background color to "black" set cursor color to "red" set normal text color to "yellow" set bold text color to "red" set title displays custom title to true set custom title to "Ethernet Address" end tell quit end tell set clip to the clipboard How do I trim to the result down to the ethernet address (xx:xx:xx:xx:xx:xx) only? OR, is there easier way... |
Try this:
do shell script "ifconfig | grep ether | sed -e 's/ether //g'" |
that helps some, but i only need, then, is the top ethernet address and have on the clipboard ready to be pasted
|
Quote:
using cwtnospam's script you can add one more pipe out to output it to a text file Code:
ifconfig | grep ether | sed -e 's/ether //g | open -a -f |
Quote:
do shell script "ifconfig | grep ether | sed -e 's/ether //g'" set the clipboard to the result |
Quote:
|
So you've got two ethernets? If you run this command in the terminal, what is the result?
ifconfig | grep ether |
By the way, it seems there are some extra characters left over after the sed command, so I did this in Applescript:
do shell script "ifconfig | grep ether | sed -e 's/ether //g'" set x to the result set y to characters 2 through 18 of x as string set the clipboard to y |
ether 00:17:f2:xx...
ether 00:17:cc:xx... ether 00:19:xx... |
ifconfig en0 | grep ether | sed -e 's/ether //g' | pbcopy
that will get me just the one, but there is some space in front of it, can that be removed |
this what i have for the final code:
do shell script "ifconfig en0 | grep ether | sed -e 's/ether //g'" set x to the result set y to characters 2 through 18 of x as string set the clipboard to y thanks for all the help everyone, it's just something to help cut down on human error when entering address into DHCP |
Ok, since you only want the first line, use this:
do shell script "ifconfig | grep -m 1 ether | sed -e 's/ether //g'" Of course, what you have works too! :o |
&
Quote:
set AppleScript's text item delimiters to ":" set IPAdresse to text items of (words 1 thru 6 of first paragraph of (do shell script "ifconfig | grep ether | sed -e 's/ether //g';)) as text set AppleScript's text item delimiters to "" but a lot easier (without spaces) is this pure-applescript-way: primary Ethernet address of (system info) Do you know how to get the IP-address in this form: "192.168.1.1"? |
it's not necessary for me to get the IP. But, I think i got it now. This didn't seem hard to do, but it finding the right commands to do it.
primary Ethernet address of (system info) set x to the result set the clipboard to x that works great and a little quicker do shell script "ifconfig en0 | grep ether | sed -e 's/ether //g'" set x to the result set y to characters 2 through 18 of x as string set the clipboard to y that works great to, plus it allows me to make sure that i get the right ethernet and could modify it to get others easier. |
Quote:
Sorry, I don't know a pure Applescript method: Code:
do shell script "ifconfig en0 | perl -pe 's/ netmask/\n/g' | grep inet | perl -pe 's/\tinet //g'" |
I use this. It returns a record: {Inside:"192.168.1.xxx", Outside:"xxx:yyy:zzz:abc"}
Quote:
|
Quote:
and the "perl-sausage" from cwtnospam is also cool, but it dosn't work correctly! (it was no test ;) ) here is my solution: word 2 of (do shell script "ifconfig en1 | grep 'inet '") and here my completed applescript-handler to get the internal ip: on getInternalIP() ***repeat with interface from 0 to 5 ******try *********set myIP to word 2 of (do shell script "ifconfig en" & interface & " | grep 'inet '") *********set result_check to true ******on error *********set result_check to false ******end try ******if result_check then exit repeat ***end repeat ***if interface is 5 then ******return "unknown" ***else ******return myIP ***end if end getInternalIP |
1 Attachment(s)
Quote:
|
I think you want to use this line
Code:
set myIP to (do shell script "ipconfig getifaddr en" & interface)set myIP to word 2 of (do shell script "ifconfig en" & interface & " | grep 'inet '") |
Quote:
|
all this solutions are needed, because the as-command:
IPv4 address of (system info) only returns "missing value" the reason for this is the virtual IP given from my router now i found another solution for this problem: last word of (do shell script "system_profiler -detailLevel basic | grep 'IPv4 Addresses'") i think, this is the most dependable way, but also the slowest. @NovaScotian (Adam Bell!): Thanx for your permission |
| All times are GMT -5. The time now is 05:51 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.