Last active
March 24, 2016 14:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
License: CC0