Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Here's how to get IP and MAC within PB

511 views
Skip to first unread message

Brian Leahy

unread,
May 1, 2013, 4:41:58 PM5/1/13
to
// And you don't even need to declare external functions, run command shells or dig through the registry...

OLEObject objWMIService, IPConfigSet, IPConfig
string s_mac, s_description, s_IP
int rs, i

objWMIService = CREATE OLEObject;
rs = objWMIService.ConnectToObject("winmgmts:{impersonationLevel=impersonate}!//./root/cimv2");

if (rs = 1) then

IPConfigSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

// Will iterate through all active network adapters

for i = 0 to (IPConfigSet.count - 1)
IPConfig = IPConfigSet.ItemIndex(i)
s_mac = (IPConfig.Properties_.Item("MACAddress").Value);
s_description = (IPConfig.Properties_.Item("Description").Value);
s_IP = (IPConfig.Properties_.Item("IPAddress").Value(0));
// Do something with the information here..
next

destroy IPConfig
destroy IPConfigSet

else
MessageBox("ERROR","Could not create OLE object");
end if;

destroy objWMIService

Brian Leahy

unread,
May 1, 2013, 4:43:45 PM5/1/13
to
Ack - slight correction.

The line:

if (rs = 1) then

SHOULD say:

if (rs = 0) then
0 new messages