Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get Network Adapter Address (MAC?)
Message
From
01/10/2001 01:14:57
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00477977
Message ID:
00562394
Views:
75
Hello Larry,
This code works fine for the machine on which it is running. I wanted to know of getting all the MAC addresses on the network.
Sanjay.


>Hi Mark,
>Try this code. I have stared using something like it since I switched to Win2K and VFP 7 because it requires WMI (and the VFP 7 IMoniker support enhancement to GetObject is required).
>omgr = GETOBJECT("WinMgmts:")
>oadaptercol = omgr.InstancesOf("Win32_NetworkAdapterConfiguration")
>IF oadaptercol.Count > 0 then
>   * go through each adapter configured on the system
>   FOR each oadapter in oadaptercol
>      if type("alen(oadapter.Properties_('IPAddress').Value)") = "N" then
>         * check was done to handle WAN adpaters that are configured on the
>         * system however they don't have IP addresses so disregard them
>         ? oadapter.Properties_('MACAddress').Value
>            for each cIP in oadapter.Properties_('IPAddress').Value
>               ? cIP
>            endfor
>      endif
>   ENDFOR
>ENDIF
>return
>
>HTH.
>
>>I have run this code multiple times on a Dell 8100 Inspiron, Win2k machine, and I get a totally different return value every time. I have found absolutely nothing that can consistently return the correct MAC address of the primary adapter.
>>
>>P.S. I do realize this thread is 7 months old. I am still searching for a way to do this and finally found this and other thread with the search engine.
>>
>>>Rick,
>>>Because a GUID uses the MAC address of the primary network adapter to make sure its unique, you can create a GUID and parse it for the MAC address.
>>>clear
>>>local lcguid
>>>lcguid = GetGUID()
>>>return substr(lcguid,26,2)+'-'+substr(lcguid,28,2)+'-'+substr(lcguid,30,2);
>>>	+'-'+substr(lcguid,32,2)+'-'+substr(lcguid,34,2)+'-'+substr(lcguid,36,2)
>>>
>>>function GetGUID
>>>local lcStrucGUID, lcGUID, lnsize
>>>declare integer CoCreateGuid in Ole32.dll string @lcGUIDStruc
>>>declare integer StringFromGUID2 in Ole32.dll string lcGUIDStruc, string @lcGUID, long lnSize
>>>
>>>lcStrucGUID=space(16)
>>>lcGUID=space(80)
>>>lnSize=40
>>>
>>>if CoCreateGuid(@lcStrucGUID) # 0 then
>>>   return ""
>>>endif
>>>if StringFromGUID2(lcStrucGUID,@lcGuid,lnSize) = 0 then
>>>  return ""
>>>endif
>>>return strconv(left(lcGUID,76),6)
>>>GetGUID code was posted by John Koziol (who I believe got it from Rick Strahl) here last year.
>>>
>>>HTH.
Sanjay Dhiraj Patel

MCSE, MCDBA

Net2Biz (Thailand)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform