Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Network Adapters

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
If oadaptcol is an array with the list of network adapters, (which it does), then how do I write the part that gives me an array that lists the ip addresses for an adapter with the "Win32_NetworkAdapter.NetworkAddresses" property and/or function?

oManager = Getobject("winmgmts:")
oadaptcol = oManager.InstancesOf("Win32_NetworkAdapter")

NetworkAddresses
Data type: string array
Access type: Read-only
Array of network addresses for an adapter. This property is inherited from CIM_NetworkAdapter.

Reference:
Thanks,
Stanley
 
stanlyn,

That's a good question...you should be able to walk that collection just like any other, but it doesn't seem to exist...hmmmm....though if you iterate through the properties_ collection and look at the Name property it is definately there...no answers yet, but looking into it

strComputer = "."
objWMIService = GetObject("winmgmts:\\" + strComputer + "\root\cimv2")
colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter",,48)
For Each objItem in colItems
? "Adapter Type: " + objItem.AdapterType
nType = objItem.AdapterTypeID
DO Case
Case nType = 0
strAdapterType = "Ethernet 802.3"
Case nType = 1
strAdapterType = "Token Ring 802.5"
Case nType = 2
strAdapterType = "Fiber Distributed Data Interface (FDDI)"
Case nType = 3
strAdapterType = "Wide Area Network (WAN)"
Case nType = 4
strAdapterType = "LocalTalk"
Case nType = 5
strAdapterType = "Ethernet using DIX header format"
Case nType = 6
strAdapterType = "ARCNET"
Case nType = 7
strAdapterType = "ARCNET (878.2)"
Case nType = 8
strAdapterType = "ATM"
Case nType = 9
strAdapterType = "Wireless"
Case nType = 10
strAdapterType = "Infrared Wireless"
Case nType = 11
strAdapterType = "Bpc"
Case nType = 12
strAdapterType = "CoWan"
Case nType = 13
strAdapterType = "1394"
ENDCASE

? "Adapter Type Id: " + strAdapterType
? "AutoSense: " + objItem.AutoSense
? "Description: " + objItem.Description
? "Device ID: " + objItem.DeviceID
? "Index: " + TRANSFORM(objItem.Index)
? "MAC Address: " + objItem.MACAddress
? "Manufacturer: " + objItem.Manufacturer
? "Maximum Number Controlled: " + TRANSFORM(objItem.MaxNumberControlled)
? "Maximum Speed: " + objItem.MaxSpeed
? "Name: " + objItem.Name
? "Net Connection ID: " + objItem.NetConnectionID
? "Net Connection Status: " + TRANSFORM(objItem.NetConnectionStatus)
*!* For Each strNetworkAddress in objItem.NetworkAddresses
*!* ? "NetworkAddress: " + strNetworkAddress
*!* ENDFOR
? "Permanent Address: " + objItem.PermanentAddress
? "PNP Device ID: " + objItem.PNPDeviceID
? "Product Name: " + objItem.ProductName
? "Service Name: " + objItem.ServiceName
? "Speed: " + objItem.Speed
endfor



Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Does the GetObject() call work for you? I'm on VFP6, and it fails with "Moniker cannot open file"
 
I wasn't able to get the IP address with
oadaptcol = ;
oManager.InstancesOf("Win32_NetworkAdapter")

But I was able to find it with
oadaptcol = ;
oManager.InstancesOf("Win32_NetworkAdapterConfiguration")

Code:
CLEAR
oManager = Getobject("winmgmts:")
oadaptcol = ;
  oManager.InstancesOf("Win32_NetworkAdapterConfiguration")
for each Qualifier in oadaptcol
   ?Qualifier.Caption
   ?Qualifier.Description
   ?Qualifier.MACAddress
   ?Qualifier.IPAddress[0]
   ?''
next

-Dave S.-
[cheers]
Even more Fox stuff at:
 
>>wgcs (Programmer) Sep 16, 2003
>>Does the GetObject() call work for you? I'm on VFP6, and >>it fails with "Moniker cannot open file"

Do you still have a snippet of what you tried which failed? If so, I'll try with it, as I'm on VFP 7...

Thanks, Stanley
 
wgcs,

GetObject() works fine for me in the code I posted above.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
wgcs,

I'm using VFP 7

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Hi slighthaze,

I'm confused when you said in your 1st post that you could not get that to work, and now you it works OK, please clarify...

Thanks,
Stanley
 
stanlyn,

The line objWMIService = GetObject("winmgmts:\\" + strComputer + "\root\cimv2") works fine for me, however the lines for looping through the objItem.NetworkAddresses collection did not produce the desired result. That is why in the code above I have commented out those lines regaerding Network Adresses. The rest of the code I posted gives me the expected results. Sorry for the confusion.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
But with those lines commented out, how are you getting the list of ip addresses, as that is what I'm after. All the other single element properties work fine. I am trying to stay away from yet another dll as in ("Win32_NetworkAdapterConfiguration"), unless it offers the same information as the "Win32_NetworkAdapter" offers, and if so, I'll switch ti it... Does it? I will be spending some time researching that next..

Thanks to DSummZZZ (Programmer)for bring that ?? to my attention. By the way, what is the proper term for "Win32_NetworkAdapterConfiguration"?

Thanks, Stanley
 
stanlyn,

You are correct I am NOT getting the IP Addresses as I would have expected. When I posted saying that GETOBJECT() works for me I was answering wgcs' question regarding it, I believe wgcs' question was referring to the GETOBJECT() line only and not to your question as a whole.

I have not as of yet been able to figure out a way to get the IP Addresses from the objItem.NetworkAddresses and I am of a mind that perhaps it cannot be done. I see some documentation that says that not all properties may be available, so this may be one of those cases. I believe that Dave may have provided you with a workable alternative.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
I'm back.

You're right, I was referring to this code:
Code:
strComputer = "."
objWMIService = GetObject("winmgmts:\\" + strComputer + "\root\cimv2")

I didn't expect VFP6/7 to be an issue: I do have VFP7, but I develop in 6 and only even added the note that I was using VFP6 as an afterthought.

I just tested with VFP7, and now that line works..... I don't understand the functionality that was added in VFP7 that makes it work, though.... I had expected it to be a feature missing on my OS version (Win2k SP5).
 
Clear
oManager = Getobject("winmgmts:")
oadaptcol = oManager.InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Qualifier In oadaptcol
* this works
?Qualifier.MACAddress

* this works
lcMac = Qualifier.Properties_('MACAddress').Value
?lcMac

* this DOES NOT work
bb = Qualifier.MACAddress
?bb

* this works, but I'm afraid it is listing only
* single element arrays
?Qualifier.IPAddress[0]

* this DOES NOT work
aa = Qualifier.IPAddress[0]
?aa

How do I assign the results that will print to the screen into a variable? The snippet above fails...

* this DOES NOT work
lcIP = Qualifier.Properties_('IPAddress[0]').Value
?lcIP

So, how how can I get the list of ip addresses into an array or a simple variable using either mentioned classes?

After researching the different classes mentioned and some others, it appears that the class "Win32_NetworkAdapter" has the richest feature set. If I could get this array list of the ip addresses figured out, it would serve us well for a long time. Getting it to work with any of those WMI classes will be fine.

The post that "DSummZZZ (Programmer)" made looked promising as well, however it seems to behave like the others, and the big fear, is that they will all fail when quering a netcard that has multiple ip addresses bound to it.

If we could just get the list of ip addresses out in any fashion, we could parse the string for the ip address we are looking for.

According to the docs I've seen the list will appear as: 123.56.89.001 24.21.21.32 101.25.36.54 (space delimited).
 
I think I made a little progress. Try this:
Code:
CREATE CURSOR AdapterDetail;
   (adProperty c(25),;
    adValue    c(120))
      
oManager = Getobject("winmgmts:")
oadaptcolconf = ;
  oManager.InstancesOf("Win32_NetworkAdapterConfiguration")

FOR EACH Qualifier IN oadaptcolconf
  FOR EACH Property IN Qualifier.Properties_
     op = Property
     IF op.IsArray
         av = Property.Value
         FOR zzz = 1 TO Alen(av)
            APPEND BLANK 
            REPLACE adProperty WITH Property.name  
            REPLACE adValue    WITH Transform(av[zzz])
         NEXT
      ELSE 
        APPEND BLANK 
        REPLACE adProperty WITH Property.name  
        REPLACE adValue    WITH Transform(Property.Value)
      ENDIF 
  NEXT
NEXT

I don't have multiple IP's bound to my adapter, so I couldn't test that. However, the 'DNSServerSearchOrder' is an array containing three entries that were separated properly. I ran this routine several times with no GPFs too.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Hi Dave,

On the line "IF op.IsArray", where are you getting the IsArray function from? No such thing in VFP7 help... If it something to the api class, please forward me a url to where they are listed and defined.

When running your code, I get an error "AV is not an array" on line "FOR zzz = 1 TO Alen(av)" It did create 6-7 records in the table, what looks like part of one adapter.

win2kp VFP7 sp1...

Thanks,
Stanley
 
stanlyn,

I am also running Win2K, but with SP4 (thanks to the latest proliferation of trojans, I updated the SP yesterday), and VFP 7.0 SP 1.

I was relying heavily on Intellisense. (Thank goodness for Intellisense).
The "IF op.IsArray" I obtained by stepping through the program until the 'op = Property' statement. Then within the command window, I would just type the '?op.' and let the Intellisense drop down and look at what was available.

I'm not sure why you would get the array error. If the op.IsError returns .T., it should be an array. The bad thing about those properties though, is that in the Locals window they don't show a value until they actually get used. So you can't just drop down the list like normal VFP variables.

Below are a handful of URLs I found that may be a little informative. But right now, I have to go do some more critical updates, so I can't check into it any more for a few minutes. Sorry.





-Dave S.-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top