How To Create This Bat File For Mac

In a batch file that uses only standard Windows commands (no third-party utilities) I need to be able to extract the MAC address of the ethernet adapter installed in the machines we deploy and display it to the user in a format like 'The MAC Address is: 00-00-00-00-00-00'. I'm running Vista Business Edition with SP1, and I've gotten close with the following (which worked under XP SP2): ipconfig /all find 'Physical Address'c: windows temp macaddress.txt for /f 'tokens=2 delims=:'%%i in (c: windows temp macaddress.txt) do @echo The MAC Address is%%i The problem is that under Vista, I end up with three MAC addresses displayed because there are multiple Physical Addresses listed in IPCONFIG's output (listed below). How can I limit the display to the Ethernet adapter's MAC address? I need to be able to extract the MAC address of the ethernet adapter installed in the machines we deploy and display it to the user in a format like 'The MAC Address is: 00-00-00-00-00-00'. ipconfig /all find 'Physical Address'c: windows temp macaddress.txt. The problem is that under Vista, I end up with three MAC addresses displayed because there are multiple Physical Addresses listed in IPCONFIG's output (listed below).

  1. How To Create This Bat File For Mac Download

How can I limit the display to the Ethernet adapter's MAC address? With something like the following. @REM locate MAC ID in ipconfig/all output @setlocal enableextensions @echo off set f=%0.tmp ipconfig/all findstr ^ /C:'Ethernet adapter Local Area Connection:' ^ /C:'Physical Address' ^ %f% for /F 'delims='%%a in (%f%) do call:PROC '%%a' echo The MAC Address is:%MACA% goto:EOF:PROC set a=%1 set a=%a: =% set a=%a.=% if '%a:0,8%' 'Ethernet' ( set s=next line will have MACA ) else if defined s ( set MACA=%a:PhysicalAddress:=% set s= ) Note: findstr.exe is a standard utility included with Windows XP.

If you have find.exe, you should also have findstr.exe. Harlan Grove 27/2/2008, 15:24 น.

Wrote in message news:%232ofBvWeIHA.4140@TK2MSFTNGP04.phx.gbl. Assuming that the address that you want is the first 'Physical Address' (you didn't say) 1SET MAC= 2ipconfig /all find 'Physical Address'c: windows temp macaddress.txt 3for /f 'tokens=2 delims=:'%%i in (c: windows temp macaddress.txt) do IF NOT DEFINED MAC SET MAC=%%i&echo The MAC Address is%%i Three lines - each prefixed by number for clarity. OR 1SET MAC= 2for /f 'tokens=2 delims=:'%%i in ( ' ipconfig /all find 'Physical Address' ' ) do IF NOT DEFINED MAC SET MAC=%%i&echo The MAC Address is%%i where the single-quotes are required but the spaces surrounding them are not - they're just there for clarity. Note that AFTER the last line of these snippets, the MAC address is available as%MAC%, there is NO spaces EITHER side of the '=' in the SET statements. See the FOR documentation for use of the.

Syntax for /? From the prompt or alt.msdos.batch.nt - where such matters are regularly discussed.

How To Create This Bat File For Mac Download

Harlan Grove 27/2/2008, 17:33 น. 'billious' wrote. Assuming that the address that you want is the first 'Physical Address' (you didn't say) 1SET MAC= 2ipconfig /all find 'Physical Address' c: windows temp macaddress.txt 3for /f 'tokens=2 delims=:'%%i in (c: windows temp macaddress.txt) do IF NOT DEFINED MAC SET MAC=%%i&echo The MAC Address is%%i Three lines - each prefixed by number for clarity. OR 1SET MAC= 2for /f 'tokens=2 delims=:'%%i in ( ' ipconfig /all find 'Physical Address' ' ) do IF NOT DEFINED MAC SET MAC=%%i&echo The MAC Address is%%i. Your approach works for the OP's sample ipconfig output, but it's not general. Your approach assigns the first physical address in the text stream to MAC, but the active Ethernet adapter need not be the first section with a physical address. On my own system, my dial-up VPN section comes before my regular (Ethernet adapter Local Area Connection) section.

Anyway, the getmac solution would be the ideal way to go. Learn something new every day. At dot 28/2/2008, 4:16 น.

Wrote in message news:eD79LPgeIHA.1188@TK2MSFTNGP04.phx.gbl. 'billious' wrote in message news:47c60c82$0$28617$a82e2bb9@reader.athenanews.com. snip Thanks, but I'm not certain that the Ethernet Adapter will always be the first physical address, which is why I specified I wanted the MAC address of the Ethernet adapter.

As to alt.msdos.batch.nt, I would normally have posted there but the news provider I have available to me at work is down, so for now I'm limited to the public Microsoft groups. RegardsDave Fair 'nuff. I'd suggest that it would be logical for the report to follow a specific structure, but then we are talking Microsoft, so there's no guarantee. You mentioned you'd used XP for your initial approach. My XP/H system doesn't include GETMAC - no idea whether it's included or a 'resource pack' or 'toolkit' inclusion with other editions or versions.

For a version that should work under XP - assuming that the MAC address is the first 'Physical Address' following 'Ethernet adapter Local Area Connection' - batch begins - 1@echo off 2set mac=&set ealac= 3for /f 'tokens=1,2 delims=:'%%i in ( ' ipconfig /all^ findstr /c:'Ethernet adapter' /c:'Physical Address' ' ) do ( 4if defined ealac if not defined mac set mac=%%j 5if not defined ealac if '%%i'Ethernet adapter Local Area Connection' set ealac=Y 6) 7echo MAC address found is%mac% 8set ealac= - batch ends - foxidrive 28/2/2008, 7:05 น. On Thu, 28 Feb 2008 22:25:25 +0800, 'billious' wrote: I'd suggest that it would be logical for the report to follow a specific structure, but then we are talking Microsoft, so there's no guarantee. You mentioned you'd used XP for your initial approach. My XP/H system doesn't include GETMAC - no idea whether it's included or a 'resource pack' or 'toolkit' inclusion with other editions or versions. Seems that it's an XP Pro tool. A monumentally stupid thing for MS to do and create multiple versions of an OS, but which they have perpetuated with Vista.

'billious' wrote in message news:47c699c6$0$2779$a82e2bb9@reader.athenanews.com. 'Dave R.' Wrote in message news:eD79LPgeIHA.1188@TK2MSFTNGP04.phx.gbl.

'billious' wrote in message news:47c60c82$0$28617$a82e2bb9@reader.athenanews.com. snip Thanks, but I'm not certain that the Ethernet Adapter will always be the first physical address, which is why I specified I wanted the MAC address of the Ethernet adapter. I'd suggest that it would be logical for the report to follow a specific structure, but then we are talking Microsoft, so there's no guarantee. As Harlan pointed out, there are at least some circumstances where the Ethernet Adapter isn't the first listed. I suspect there is a 'convention' of sorts that is followed, but it may not be something that makes sense to you and I. You mentioned you'd used XP for your initial approach. My XP/H system doesn't include GETMAC - no idea whether it's included or a 'resource pack' or 'toolkit' inclusion with other editions or versions.

It is included in XP Pro, so must be one of the things MS decided that Home users don't need, like Domains. 'foxidrive' wrote in message news:dajds3957tnn12u1amdhmmiannomvaupjf@4ax.com. On Thu, 28 Feb 2008 22:25:25 +0800, 'billious' wrote: I'd suggest that it would be logical for the report to follow a specific structure, but then we are talking Microsoft, so there's no guarantee. You mentioned you'd used XP for your initial approach. My XP/H system doesn't include GETMAC - no idea whether it's included or a 'resource pack' or 'toolkit' inclusion with other editions or versions.

For

Seems that it's an XP Pro tool. A monumentally stupid thing for MS to do and create multiple versions of an OS, but which they have perpetuated with Vista. Thought they learned that lesson with DOS5 (well, let's forget DOS4 - and the way it's beginning to look, forget Vista, too) It needs some extra logic - here is what mine says: Ethernet adapter Local Area Connection 4: Curious. Any clue as to why '4'?

Are there 0.3 as well, or just '4' for the sake of '4'? How about - batch begins - 1@echo off 2setlocal enabledelayedexpansion 3set mac=&set ealac= 4for /f 'tokens=1,2 delims=:'%%i in ( ' ipconfig /all^ findstr /c:'Ethernet adapter' /c:'Physical Address' ' ) do ( 5if defined ealac if not defined mac set mac=%%j 6if not defined ealac echo%%i find 'Ethernet adapter Local Area Connection' nul&if not errorlevel 1 set ealac=Y 7) 8echo MAC address found is%mac% - batch ends - (relying on 'E.a.L.A.C' being unique for the block of;ines in question - but why '4'???) foxidrive 28/2/2008, 9:23 น.

On Fri, 29 Feb 2008 01:02:54 +0800, 'billious' wrote: It needs some extra logic - here is what mine says: Ethernet adapter Local Area Connection 4: Curious. Any clue as to why '4'? Cooler for mac.

Are there 0.3 as well, or just '4' for the sake of '4'? Every time you change LAN cards it will increment the number - ditto with Wireless connections. 'Mark Blain' wrote in message news:Xns9A52B206476B8mblainalbany@207.46.248.16.

There is that, (although I think most are willing to read, and even respond if the poster behaves reasonably well), but after a lifetime of using newsreaders of one variety or another I find the Google Groups web interface unmanageable. Old dog / new tricks perhaps, but for the odd post during the (hopefully) short time I'll be without my regular news provider, if there is an alternative to Google Groups I'll use it. Regards, Dave.

Comments are closed.