WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

TCPIP and IP Address

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get MAC (Media Access Control) IP Address Under Windows NT

Keywords:    MAC    Media Access Control   NIC address servicename service name

Question:

How do I get my MAC IP address (aka NIC (Network Interface Card) address) under Windows NT?

Answer:

I recommend using WMI:
strComputer = "."
objWMIService = GetObject(StrCat("winmgmts:!\\" , strComputer , "\root\cimv2"))
colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True AND DHCPEnabled = True")
ForEach objAdapter in colAdapters
	MACAddress  = objAdapter.MACAddress 
	Message("MAC Address",MACAddress)
Next
User comment:

We've have found a way to get the MAC and IP address info from NT workstations. Give this a try.

Basically, it gets the service name from the registry and then checks the card specific info in the registry.

User's note:

Note that the following value will often hold the NIC's MAC address. In some situations however, this value is NOT the same as the NIC MAC Address and is just a unique value, so this is not really a sure fire way of obtaining this information.

The following Key:

MACaddress=RegQueryBin(@REGMACHINE,"SOFTWARE\Description\Microsoft\Rpc\UuidTemporaryData\[NetworkAddress]")
IS NOT REALY THE MAC-ADDRESS, I've found the following information on the key UUID... "This value will often hold the NIC's MAC address (which supposedly fulfils the statistically unique requirement). In many situations however, this value is NOT the same as the NIC MAC Address and is just a unique value."

I've had to build in this function into our network login script, then during some tests we experienced some strange things, after some minutes of troubleshooting we've found the solution above.


Another user reports:

The IP Address is, I have found, more than 'tricky.' Down right nasty is more like it.

NT4 keeps track of installed nics under "HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkCards" and gives them numbers based on order installed. (Can get messy though with uninstalls and reinstalls/other installs)

Check the Value of the [ServiceName] value under the desired nic(easier said than decided, you could use the [ProductName] value to decide, but can still be tricky.. I default to the first and ask if would like the others instead...) and use that value to look under "HKLM\System\CurrentControlSet\Services\%ServiceName%\Parameters\Tcpip[IPAddress]" (Substituting the value of [ServiceName] you got just before) Careful... It's a multi-string value, if you have multiple IP addresses bound to the nic, they will all be in there, yet another decision to make...

95 is tricker due to Plug and Play support. Briefly: You must search "HKLM\Enum" for [Class] = "Net" and then read the valuenames under the Bindings key of the key who has the [Class] = "Net". For TCPIP you should look for "MSTCP\0000" where 0000 is the number assigned to the nic by 95. Follow that value to "HKLM\Enum\Network\MSTCP\0000" ,where 0000 is the number of your nic, and read the [Driver] value there, should be something to the effect of "NetTrans\0000" and you will follow that to "HKLM\System\CurrentControlSet\Services\Class\NetTrans\0000" where you will find your [IPAddress] value for that nic.

And if you thought that was bad, this doesn't even consider the possibility of DHCP! ]:)~

Of course, if you have a standard environment, you can make some serious shortcuts. You might even be able to circumvent the system by parsing the output of ipconfig in NT4. Good Luck...

P.S. 98 does it differently also!

Be sure to look at other articles in the DB that relate to this issue, namely article IDs: W12652, W12653, W12654, W12340, W12655, W12345.


ServiceName=RegQueryValue(@REGMACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1[servicename]")

MACaddress=RegQueryBin(@REGMACHINE,"SOFTWARE\Description\Microsoft\Rpc\UuidTemporaryData[NetworkAddress]")

IPRegKey=RegOpenKey(@REGMACHINE,"SYSTEM\CurrentControlSet\Services\%ServiceName%\Parameters\Tcpip")
IPaddress=RegQueryMulSz(IPRegKey,"[IPAddress]",@tab)
RegCloseKey(IPRegKey)

message("","Service Name = %ServiceName%%LF%Ip Address = %IPaddress%%LF%Macaddress = %Macaddress%")


Article ID:   W13484
Filename:   Get MAC Address (Reg Method).txt
File Created: 2005:12:14:13:40:18
Last Updated: 2005:12:14:13:40:18