Skip to content

Instantly share code, notes, and snippets.

@rodrigolive
Created March 4, 2021 17:52
Show Gist options
  • Save rodrigolive/7c286144ba66025708f9b19c991fab8f to your computer and use it in GitHub Desktop.
Save rodrigolive/7c286144ba66025708f9b19c991fab8f to your computer and use it in GitHub Desktop.
ex04 - MAC
#!/bin/bash
ifconfig -a link | grep ether | sed 's/^.*ether //'
@rodrigolive
Copy link
Author

El comando ifconfig (interface config) del ejercicio saca un listado completo de todas las interfaces de red, son sus MAC, IP address, nombres y otros cosas más.

Cada interfaz de red del ordenador, ej, una antena wi-fi, una entrada de cable Ethernet, etc etc, tiene una MAC-address. Para limitar la salida del ifconfig a solo la MAC address, ponemos -a link como parámetro.

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	options=400<CHANNEL_IO>
	ether 50:ed:3c:05:cd:73

Aún así la salida tiene mucha basura. Así que filtramos la salida solo las líneas que contienen la palabra ether utilizando el fantástico comando grep y pasándole como parámetro ether

 grep ether

El resultado son estas líneas:

$ ifconfig -a link|grep ether
	ether 1c:02:e4:4a:7a:50
	ether 1c:02:e9:4a:7a:51
	ether 1c:02:e9:4a:7a:30
	ether 1c:02:e9:4a:7a:31
	ether 3b:01:7b:bc:5d:80
	ether 3b:01:7b:bc:5d:84
	ether 7b:e2:3c:04:cd:73
	ether 5b:e2:3c:04:cd:72
	ether 3b:02:7c:ba:5d:80
	ether 8c:02:58:4b:a3:35

A continuación las limpiamos utilizando nuestro amigo sed reemplazador:

sed 's/^.*ether //'

Reemplazando cada línea desde el principio (^) todo y cualquier caracter intermedio (.*) hasta la palabra ether y el espacio a continuación.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment