Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File to get MAC Addresses  (Read 58144 times)

0 Members and 1 Guest are viewing this topic.

Fiala06

    Topic Starter


    Rookie

    Thanked: 1
    Batch File to get MAC Addresses
    « on: January 04, 2011, 09:32:05 AM »
    Hey guys can anyone help me create a batch file that will get the mac address off multiple machines and save it to a network file?

    I have a lab of 60 desktops and would like to run a batch file on each machine that will find the MAC address and save it to a internal server such as \\server1\folder1\folder2\macaddress.txt

    Thanks

    JoshM



      Beginner
    • I'm so ahead of my time my parents haven't met yet
      • Experience: Experienced
      • OS: Windows 7
      Re: Batch File to get MAC Addresses
      « Reply #1 on: January 04, 2011, 12:10:54 PM »
      I can't help you with this but I defiantly would like to know how to do this as well  ;D

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Batch File to get MAC Addresses
      « Reply #2 on: January 04, 2011, 12:31:35 PM »
      I found this, it may help.
      I was trying to dereference Null Pointers before it was cool.

      Fiala06

        Topic Starter


        Rookie

        Thanked: 1
        Re: Batch File to get MAC Addresses
        « Reply #3 on: January 04, 2011, 02:00:26 PM »
        Thanks for that link BC! I've been playing with:

        Code: [Select]
        ipconfig /all|find "Physical Address">>\\district5\Common\Public\macadd.txt
        for /f "tokens=2 delims=:" %%i in (\\district5\Common\Public\macadd.txt) do
        @echo The MAC Address is %%i

        Seems to be working fine except I don't know how to separate each entry with a break line or something....

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Batch File to get MAC Addresses
        « Reply #4 on: January 04, 2011, 04:51:22 PM »
        I added a random number to the output file name so each file on the server would be unique. Also added the computer name to the output file so you could distinguish the MAC addresses. Otherwise you had it just about right.

        Code: [Select]
        @echo off
        for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i "Physical Host"') do (
          echo %%i >> \\server1\folder1\folder2\macadd%random%.txt
        )

        Good luck.  8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        ghostdog74



          Specialist

          Thanked: 27
          Re: Batch File to get MAC Addresses
          « Reply #5 on: January 04, 2011, 09:29:16 PM »
          you can use getmac. see getmac /? for more info.

          Fiala06

            Topic Starter


            Rookie

            Thanked: 1
            Re: Batch File to get MAC Addresses
            « Reply #6 on: January 04, 2011, 09:57:39 PM »
            Ahh thanks for all your help guys. I have it all setup now the way I want it and ready to deploy it tomorrow!!!

            Thanks again!

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Batch File to get MAC Addresses
            « Reply #7 on: January 04, 2011, 10:07:19 PM »
            you can use getmac. see getmac /? for more info.

            Also: I think that tool would be available via a resource kit for W2K and earlier (it's included in XP Pro and up). (just checked, it's in the NT4 resource kit and no doubt is in the w2k one). I doubt they are  running an OS before XP on any of the machines anyways, though.

            The batch method will work with NT4 and 2000 (not as sure about NT4).

            getmac would be the better solution regardless- it's designed for the very purpose required.

            I was trying to dereference Null Pointers before it was cool.

            Fiala06

              Topic Starter


              Rookie

              Thanked: 1
              Re: Batch File to get MAC Addresses
              « Reply #8 on: January 04, 2011, 10:16:47 PM »
              O yea should of mentioned its for XP and Win7 ;)

              ghostdog74



                Specialist

                Thanked: 27
                Re: Batch File to get MAC Addresses
                « Reply #9 on: January 04, 2011, 10:28:51 PM »

                The batch method will work with NT4 and 2000 (not as sure about NT4).
                I may be wrong, but i see no options of ipconfig that can query a set of remote addresses. if OP has 60 desktops to process, then ipconfig may  not work as well as getmac.

                Fiala06

                  Topic Starter


                  Rookie

                  Thanked: 1
                  Re: Batch File to get MAC Addresses
                  « Reply #10 on: January 04, 2011, 10:33:03 PM »
                  Here is what I ended up with and will work just fine for what were doing.


                  Code: [Select]
                  echo ------------------------------------------------ >>\\server\Common\Public\getmac\MV-mac.txt
                  echo ------------------------------------------------ >>\\server\Common\Public\getmac\MV-mac.txt
                  echo %date% >>\\server\Common\Public\getmac\MV-mac.txt
                  echo %COMPUTERNAME% >>\\server\Common\Public\getmac\MV-mac.txt
                  echo %username%>>\\server\Common\Public\getmac\MV-mac.txt


                  ipconfig /all|find "Physical Address" >>\\server\Common\Public\getmac\MV-mac.txt
                  for /f "tokens=2 delims=:" %%i in (\\server\Common\Public\getmac\MV-mac.txt) do
                  @echo The MAC Address is %%i

                  ghostdog74



                    Specialist

                    Thanked: 27
                    Re: Batch File to get MAC Addresses
                    « Reply #11 on: January 04, 2011, 10:48:30 PM »
                    Here is what I ended up with and will work just fine for what were doing.


                    Code: [Select]
                    echo ------------------------------------------------ >>\\server\Common\Public\getmac\MV-mac.txt
                    echo ------------------------------------------------ >>\\server\Common\Public\getmac\MV-mac.txt
                    echo %date% >>\\server\Common\Public\getmac\MV-mac.txt
                    echo %COMPUTERNAME% >>\\server\Common\Public\getmac\MV-mac.txt
                    echo %username%>>\\server\Common\Public\getmac\MV-mac.txt


                    ipconfig /all|find "Physical Address" >>\\server\Common\Public\getmac\MV-mac.txt
                    for /f "tokens=2 delims=:" %%i in (\\server\Common\Public\getmac\MV-mac.txt) do
                    @echo The MAC Address is %%i

                    so you have to run it on EVERY machine ? if you have  a list of ip address or computer names of those 60 machines, you can use getmac with /S to query them all without having to go to every machine and run it.

                    BC_Programmer


                      Mastermind
                    • Typing is no substitute for thinking.
                    • Thanked: 1140
                      • Yes
                      • Yes
                      • BC-Programming.com
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Beginner
                    • OS: Windows 11
                    Re: Batch File to get MAC Addresses
                    « Reply #12 on: January 04, 2011, 11:25:30 PM »
                    I may be wrong, but i see no options of ipconfig that can query a set of remote addresses. if OP has 60 desktops to process, then ipconfig may  not work as well as getmac.
                    Quote
                    I have a lab of 60 desktops and would like to run a batch file on each machine
                    Not remote. Of course a option that means they don't have to run it on each machine would be easier. Especially since it is part of the OS's in use. (and you really only need one machine that has getmac to get the various addresses)
                    I was trying to dereference Null Pointers before it was cool.

                    Fiala06

                      Topic Starter


                      Rookie

                      Thanked: 1
                      Re: Batch File to get MAC Addresses
                      « Reply #13 on: January 05, 2011, 10:00:41 AM »
                      so you have to run it on EVERY machine ? if you have  a list of ip address or computer names of those 60 machines, you can use getmac with /S to query them all without having to go to every machine and run it.

                      Well either way I have to touch them all. These are all new computers with an image I use. There all setup with DHCP so I'll have no idea what the IP's are. We need the mac address's so we can reserve address's on our servers for each individual machine.


                      DaveLembke



                        Sage
                      • Thanked: 662
                      • Certifications: List
                      • Computer: Specs
                      • Experience: Expert
                      • OS: Windows 10
                      Re: Batch File to get MAC Addresses
                      « Reply #14 on: January 10, 2011, 07:55:11 PM »
                      Retracted suggestion after re-reading last post.