Getting MAC Address by code


Hi, I've compiled this example:


GetMACAddress


to get MAC Address on Pandora, but it don't works, I get the message: ''can't get MAC address''.


Any suggestions or example code ?


Thanks.

That code worked for me, I compiled it using the compiler tools bundled into the PND.. I noticed you need to enable the wifi or USB network device for this code to work.. if the Wifi is off or another network device isn't present it will only show the lo device when using the ifconfig command, which doesn't have a MAC address.
 
Last edited by a moderator:
Why don't you just fetch the result from executing a shell script?



Code:
ifconfig | awk '/HWaddr/{print $5}'

or to fetch a specific interface:



Code:
ifconfig wlan0 | awk 'HWaddr/{print $5}'
 
I was going to write back something similar, but gave the benefit of the doubt Geca needed to do it this way.. So I tried out the code he provided which seems to work fine.


Both methods would need the Wifi or other network device to be turned on.
 
Thanks guys. Yes I need to do it this way, the problem is I need to activate the wifi to get the mac address, any offline solutions ?! :(

Well you could make a script or run a system command with in the program to enable the wifi prior to running the mac address code and then disable it when it's finished... I'm not saying it's the only way.. but as far as I know you can't figure out the MAC address on the fly other wise.
 
You seem to have a reason for preferring not to use a script, however I'm going to list one anyway as others trying to solve the same problem are likely to stumble upon this thread.


This script will activate WiFi if it is turned off, fetch the MAC address of the wireless adapter and then deactivate WiFi if it was originally off. If it was already running, its status is left untouched.



Code:
#!/bin/bash


tmpwifi=$(ifconfig | grep -c wlan0)


if [ 0 -eq $tmpwifi ]; then

    /usr/pandora/scripts/pnd_run.sh -p "/usr/pandora/apps/op_wifi.pnd" -e "op_wifi.sh" -b "op_wifi"

fi


ifconfig wlan0 | awk '/HWaddr/{print $5}'


if [ 0 -eq $tmpwifi ]; then

    /usr/pandora/scripts/pnd_run.sh -p "/usr/pandora/apps/op_wifi.pnd" -e "op_wifi.sh" -b "op_wifi"

fi

To incorporate this into a C program use a function like e.g. popen to start the script and fetch the result.
 
Back
Top