You need to know the MAC address (eth0, for example). besides mac'if ifconfig produces a bunch of unnecessary garbage to me. I thought to isolate the conclusion of the regular, but I do not know how. That that found checked a line for compliance, but did not make search / preservation in an array.
- So maybe not from ifconfig to take, but from cat / sys / class / net / * / address? - FeroxTL
- Yes, thank you, it worked. - WhereColdWindsBlow
|
1 answer
although the ifconfig program is morally and physically outdated for management, diagnostic, and information purposes in operating systems that use the linux program as a kernel, I will give an example for it:
$ x=$(/sbin/ifconfig ΠΈΠΌΡ-ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ°); x=${x#*HWaddr }; x=${x%% *}; echo $x 11:22:33:44:55:66 or, not "on pure bash":
$ /sbin/ifconfig ΠΈΠΌΡ-ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ° | awk '/HWaddr/ {print $5}') 11:22:33:44:55:66 and using the current ip program from the iproute2 software package , for example:
$ x=$(ip -ol sh ΠΈΠΌΡ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ°); x=${x#*ether }; x=${x%% *}; echo $x 11:22:33:44:55:66 or, if the virtual sysfs file system is mounted, then it is even shorter:
$ cat /sys/class/net/ΠΈΠΌΡ-ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ°/address 11:22:33:44:55:66 for more information about shell parameter expansion in the bash program, see the documentation .
|