Skip to content

Instantly share code, notes, and snippets.

@kindfulkirby
Last active March 24, 2016 14:42
Show Gist options
  • Save kindfulkirby/36afcae695b3fb9757cc to your computer and use it in GitHub Desktop.
Save kindfulkirby/36afcae695b3fb9757cc to your computer and use it in GitHub Desktop.
Raspberry PI: If pin 21 is pulled to ground (just connect the two pins at the USB end of the GPIO header, preferrably put a jumper over them) write MAC addresses to file
import fcntl, socket, struct
import RPi.GPIO as GPIO
def get_mac(interface):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', interface[:15]))
return ':'.join(['%02x' % ord(char) for char in info[18:24]])
except(IOError):
return ""
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(21, GPIO.IN, GPIO.PUD_UP)
if GPIO.input(21) == False: #False == LOW, i.e. ACTIVE!
f = open('/home/pi/jukebox/static/help_local.html', 'w')
f.write("eth0: " + get_mac("eth0") + "<br>")
f.write("wlan0: " + get_mac("wlan0"))
f.close()
GPIO.cleanup()
@kindfulkirby
Copy link
Author

License: CC0

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