2014-11-03 45 views
0

我在工作的某些机器上使用LAN唤醒应用程序,并且我正在创建一个脚本以在实验室中对其进行测试。插入Hyphon每两个字符批量

不幸的是,应用程序只读取没有hyphon的MAC地址(从.csv文件),并且为了检查机器是否被“唤醒”,机器需要被ping通。我已经找到了一种使用ARP的方法,但是,MAC地址需要将其中的hyphon放回到ARP表中。

基本上,我需要能够在MAC地址中插入每两个字符(优选在脚本)一个hyphon,因此,该过渡将是如下:

XXXXXXXXXXXX - > XX-XX-XX -XX-XX-XX

的脚本内容:

for /f %%a in (macaddresses.csv) do (
    start "" wol.exe %%a 
    :: CONVERSION HERE 
    for /f "tokens=1,2,3 delims= " %%i in ('arp -a ^| find /i "%%a"') do (
     ping %%i 
     if %errorlevel% EQU 0 (
      echo MAC address %%a woken up. 
      set /a i+=1 
     ) else (
      echo MAC address %%a not woken up. 
     ) 
    ) 
) 

我已经到处找,发现只有如何从一个字符串的结尾或从文字中添加或删除角色。

在此先感谢!

回答

2

设法通过增量去除字符我想要的东西:

setlocal enableextensions enabledelayedexpansion 
for /f %%a in (macaddresses.csv) do (
    start "" wol.exe %%a 
    set mac=%%a 
    set mac=!mac:~0,-10!-!mac:~2,-8!-!mac:~4,-6!-!mac:~6,-4!-!mac:~8,-2!-!mac:~10! 
    for /f "tokens=1,2,3 delims= " %%i in ('arp -a ^| find /i "!mac!"') do (
     ping %%i 
     if %errorlevel% EQU 0 (
      echo MAC address !mac! woken up. 
      set /a i+=1 
     ) else (
      echo MAC address !mac! not woken up. 
     ) 
    ) 
) 
endlocal