+ Post New Thread
Results 1 to 11 of 11
Windows Thread, logging mac codes in Technical; i made a bit in the staff login script that writes laptop mac/ethernet ads to a log file but because ...
  1. #1
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,529
    Thank Post
    108
    Thanked 89 Times in 75 Posts
    Blog Entries
    47
    Rep Power
    41

    logging mac codes

    i made a bit in the staff login script that writes laptop mac/ethernet ads to a log file but because i've scraped it off the ipconfig cmd the string which has the mac ad in also contains a non alphanumeric character at the end that prevents me from creating a file with the mac as the name

    Code:
    del \\backup\logs$\lapmacs\%computername%.log /q
    for /f "tokens=2 delims=:" %%a in ('ipconfig /all ^| find "physical" /i ') do (
    rem echo %computername% >> \\backup\logs$\lapmacs\%%a.log
    echo %%a >> \\backup\logs$\lapmacs\%computername%.log
    )
    anyone know how to get rid of his chr? thx

  2. #2
    Scruff's Avatar
    Join Date
    May 2007
    Location
    Lincs
    Posts
    137
    Thank Post
    16
    Thanked 3 Times in 3 Posts
    Rep Power
    16

    Re: logging mac codes

    this is psudo so probably not syntactically correct but i'd do something like



    %%a = left(%%a,len(%%a)-1) to remove the last 1 char

    edit: even messed it up in theory there , that looks better

    you probably don't have access to any of those functions though unfortunately

  3. #3

    Join Date
    Feb 2006
    Location
    Derbyshire
    Posts
    1,381
    Thank Post
    181
    Thanked 211 Times in 171 Posts
    Rep Power
    65

    Re: logging mac codes

    i'd hate trying to manipulate strings with FOR so I'd be tempted to make a copy of gawk available in the netlogon dir... then...

    ipconfig /all | find /i "physical" | gawk {"print \"set PCMAC=\" $12"} > tmp.bat
    call tmp.bat
    echo %COMPUTERNAME% > %PCMAC%.TXT
    del tmp.bat

  4. #4

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,609
    Thank Post
    730
    Thanked 1,688 Times in 1,502 Posts
    Rep Power
    433

    Re: logging mac codes

    vbscript might be a better way then you can use string manipulation easily:

    http://www.dbforums.com/archive/index.php/t-885289.html

    http://www.microsoft.com/technet/scr...ltivalued.mspx

    Ben

  5. #5

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,820
    Thank Post
    110
    Thanked 590 Times in 511 Posts
    Blog Entries
    1
    Rep Power
    226

    Re: logging mac codes

    Also consider ArpWatch.

  6. #6
    Scruff's Avatar
    Join Date
    May 2007
    Location
    Lincs
    Posts
    137
    Thank Post
    16
    Thanked 3 Times in 3 Posts
    Rep Power
    16

    Re: logging mac codes

    I just ran the script and the variable contains both leading and trailing blank characters, i'd be tempted to write a .vbs that returns a trim()'d version of the input and call it using

    ('cscript.exe //Nologo %variablehere%')

    you can then set a var using the output of the vbs

    I'll give it a go today and post if it works

  7. #7
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,529
    Thank Post
    108
    Thanked 89 Times in 75 Posts
    Blog Entries
    47
    Rep Power
    41

    Re: logging mac codes

    Quote Originally Posted by Scruff
    I just ran the script and the variable contains both leading and trailing blank characters, i'd be tempted to write a .vbs that returns a trim()'d version of the input and call it using

    ('cscript.exe //Nologo %variablehere%')

    you can then set a var using the output of the vbs

    I'll give it a go today and post if it works
    cool that seems to be the way forward.

  8. #8
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: logging mac codes

    Assuming you are assigning IPs with DHCP, it should be possible to extract MACs from there. There is a freeware utility SpecOps GpUpdate which uses this technique to do WOL against computer accounts in AD.

  9. #9
    Scruff's Avatar
    Join Date
    May 2007
    Location
    Lincs
    Posts
    137
    Thank Post
    16
    Thanked 3 Times in 3 Posts
    Rep Power
    16

    Re: logging mac codes

    OK, job done!

    what you need to do in your \\backup\logs$\lapmacs\ directory is create a file called enumerate.vbs (that's what i called it anyway) with the following in it

    Dim objFileSystem, objOutputFile
    Dim strOutputFile

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

    For each objItem in colItems
    'Wscript.Echo objItem.MACAddress
    strOutputFile = "\\backup\logs$\lapmacs\" & Replace(objItem.MACAddress,":","-") & ".log"
    Set objFileSystem = CreateObject("Scripting.fileSystemObject")
    Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
    Set WshNetwork = WScript.CreateObject("WScript.Network")

    objOutputFile.WriteLine(WshNetwork.ComputerName)
    Set objFileSystem = Nothing

    Next
    then you need to add the following line into the code you pasted earlier:

    cscript.exe //NOLOGO \\backup\logs$\lapmacs\enumerate.vbs
    worked for me, hope it helps

    Edit: sorry i pasted that straight from getting it to work, i probably should have tidied it up a bit, but i'm sure you can see what it's doing and make it a bit nicer

  10. #10
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,529
    Thank Post
    108
    Thanked 89 Times in 75 Posts
    Blog Entries
    47
    Rep Power
    41

    Re: logging mac codes

    cool thx. however ive simplified it somewhat.

    strip.vbs

    Code:
    Set objArgs = WScript.Arguments
    WScript.Echo trim(cstr(objArgs(0)))
    in login script bat

    Code:
    rem log mac addresses
    del \\backup\logs$\lapmacs\%computername%.log /q >nul
    for /f "tokens=2 delims=:" %%a in ('ipconfig /all ^| find "physical" /i ') do (
    	for /f %%b in ('cscript //nologo \\server1\netlogon\strip.vbs %%a') do (
    		echo %computername% > \\backup\logs$\lapmacs\%%b.log
    		echo %%b >> \\backup\logs$\lapmacs\%computername%.log
    	)
    )

  11. #11
    Scruff's Avatar
    Join Date
    May 2007
    Location
    Lincs
    Posts
    137
    Thank Post
    16
    Thanked 3 Times in 3 Posts
    Rep Power
    16

    Re: logging mac codes

    Hah, I had exactly the same thing earlier on in the day but I prefered for the vbs to pull the machine information as it's tidier than stripping strings from a cli output

    But whatever makes you happy

SHARE:
+ Post New Thread

Similar Threads

  1. Logging onto the network after logging on locally
    By frankybaloney in forum Windows
    Replies: 9
    Last Post: 10th October 2008, 12:17 PM
  2. Compaq Presario V2000 Beep Codes?
    By philjones2000 in forum Hardware
    Replies: 0
    Last Post: 11th December 2007, 01:58 PM
  3. Replies: 0
    Last Post: 10th December 2007, 04:48 PM
  4. Nvidia Model codes - whats best? GS/GTS/GT
    By j17sparky in forum Hardware
    Replies: 21
    Last Post: 4th December 2007, 01:02 PM
  5. exam-codes
    By callumtuckey in forum General Chat
    Replies: 14
    Last Post: 24th August 2007, 09:52 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •