Namespaces
Variants
Actions

How to get MAC address of a WLAN device

Jump to: navigation, search
Article Metadata

Article
Created: sathish.sh (27 Jun 2007)
Last edited: hamishwillee (03 Feb 2012)

The MAC address of a WLAN device can be retrieved by the code *#MAC0WLAN# on the standby screen (that's same as *#62209526#).

We can get the MAC address of a S60 WLAN device programmatically as well. This can be done by the following code snippet.

Header:

#include <in_sock.h>

Link against:

LIBRARY insock.lib

Capabilities:

CAPABILITY NONE
RSocketServ socketServ;
User::LeaveIfError(socketServ.Connect());
CleanupClosePushL(socketServ);
 
// Open a socket
RSocket socket;
User::LeaveIfError(socket.Open (socketServ,KAfInet,KSockStream,KProtocolInetTcp));
CleanupClosePushL(socket);
 
// Start enumerating the interfaces
TPckgBuf<TSoInetInterfaceInfo> info;
socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
TBuf<32> macAddr;
 
while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info) == KErrNone)
{
if(info().iName.FindF(_L("Wlan")) == KErrNotFound)
continue;
 
macAddr.Zero();
for(TUint i = sizeof(SSockAddr) ; i < sizeof(SSockAddr) + 6 ; i++)
if(i < (TUint)info().iHwAddr.Length())
macAddr.AppendFormat(_L("%02X:"), info().iHwAddr[i] );
 
if(macAddr.Length()) // remove trailing ':'
macAddr.Delete(macAddr.Length()-1, 1);
}
CleanupStack::PopAndDestroy(2);

However, the above MAC address retrieval code works only when your phone is connected to a WLAN. To find out the MAC address even with WLAN turned off, see the below alternative solution (applies to all S60 3rd Edition devices and S60 3rd Edition Feature Pack 1 devices):

This alternatively method uses the Publish and Subscribe keys to retrieve the MAC address when the WLAN is turned off.

WLAN Info API, a part of the Extensions plug-in package for S60 3rd Edition, Feature Pack 1 Software Development Kit, contains Publish and Subscribe keys with a MAC address for the WLAN interface.

The wlaninternalpskeys.h header file contains the required Publish and Subscribe category and key information:

const TUid KPSUidWlan = { 0x101f8ec5 };
const TUint KPSWlanMacAddress = 0x00000001;
const RProperty::TType KPSWlanMacAddressType = RProperty::EByteArray;

Comments

Reviewer-approved.png
10 Sep
2009
Article Review by User:FireSwarog (20090910)

This code snippet demonstartes how to obtain WLAN address of the current device. It works fine, but only if the device is now connected to WLAN. Sometimes such information is very important, especially for identification.

This code snippet works fine on my Nokia 5800.


Reviewer-approved.png
09 Sep
2009
Article Review by kamalakshan (20090909)

This article provides code snippet for reading the MAC address of a WLAN device. It has provided enough information on both scenarios when the WLAN is on and off. MAC address is sometimes used by applications along with other ID's like IMEI to identify and track users.
This page was last modified on 3 February 2012, at 02:15.
2148 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2012 All rights reserved