Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

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

 

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

Posted

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

Posted

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

Posted

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

Posted
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.

Posted

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

Posted

cool thx. however ive simplified it somewhat.

 

strip.vbs

 

Set objArgs = WScript.Arguments
WScript.Echo trim(cstr(objArgs(0)))

 

in login script bat

 


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
)
)

Posted

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 :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...