Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to retrieve a NIC Mac Address and its IP
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 7
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
00996178
Message ID:
00996179
Vues:
34
>Hi,
>
>I think somebody has posted this subject not long ago. Can somebody lead me to the right thread? Or can somebody post it here?
>
>Thanks.
lparameters tcComputer, tcUser, tcPassword
local loWMI, colNetAdapters, loNetAdapter, lcComputer

lcComputer    = Iif(Vartype(tcComputer) = "C" and not Empty(tcComputer), tcComputer, ".")
lcUser        = iif(vartype(tcUser) = "C", tcUser, "")
lcPassword    = iif(vartype(tcPassword) = "C", tcPassword, "")

lcDomain     = getenv('USERDNSDOMAIN')
loLocator    = createobject('WbemScripting.SWbemLocator')
try
    if empty(lcUser)
        loWMI        = loLocator.ConnectServer(lcComputer)
    else
        loWMI        = loLocator.ConnectServer(lcComputer, 'root\cimv2', lcUser, lcPassword)
    endif
catch
    loWMI        = null
endtry

if not isnull(loWMI)
    loNetAdapters    = loWMI.ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled='true' and DNSDomain='" + lcDomain + "'"")

    For Each loNetAdapter in loNetAdapters
        ? loNetAdapter.Caption, loNetAdapter.MACAddress
        for each lcIP in loNetAdapter.IPAddress
            ?? Chr(9), lcIP
        endfor
        ?
    Endfor
endif
This code contains parts that are not required if you are interested just in the local computer, it is intended to be used to get MAC/IP(s) of any computer in the network, if you have enough rights. You can see that the IP can be more than one, that is why there is an inner loop.
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform