Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_log_ip_mac_wmic.bat

(view source code of login_log_ip_mac_wmic.bat as plain text)

  1. SETLOCAL ENABLEDELAYEDEXPANSION
  2. SET WMIPath=Path Win32_NetworkAdapter
  3. SET WMIQuery=WHERE "AdapterType LIKE 'Ethernet%%' AND MACAddress > '' AND NOT PNPDeviceID LIKE 'ROOT\\%%'"
  4. FOR /F "tokens=*" %%A IN ('WMIC %WMIPath% %WMIQuery% Get MACAddress /Format:List ^| FIND "="') DO SET %%A
  5. SET WMIPath=Path Win32_NetworkAdapterConfiguration
  6. SET WMIQuery=WHERE "MACAddress='%%MACAddress%%'"
  7. FOR /F "tokens=*" %%A IN ('WMIC %WMIPath% %WMIQuery% Get IPAddress /Format:List ^| FIND "="') DO (
  8. 	FOR /F "tokens=2 delims==" %%B IN ("%%~A") DO (
  9. 		IF NOT "%%~B"=="" (
  10. 			FOR /F "tokens=1 delims={}" %%C IN ("%%~B") DO (
  11. 				SET IPAddress=!IPAddress!,%%~C
  12. 			)
  13. 		)
  14. 	)
  15. )
  16. >> \\Server\Logs\%Today%\%UserName%.log ECHO.%IPAddress:~1%,%MACAddress::=%
  17. ENDLOCAL

page last modified: 2024-04-16; loaded in 0.0093 seconds