@ECHO OFF & setLocal enableDelayedExpansion
::設定網段
set Range=10.10.1.1-254
::設定超時時間(毫秒)
set Timeout=5
::設定資料大小(位元組)
set Bytes=1
::設定輸出檔名
set FName=%date:~,4%%date:~5,2%%date:~8,2%%time::=%
set FName=%FName: =0%
set "FName=線上IP_%FName:.=%.txt"
::臨時IP列表
set "IPList=%temp%\IPs"
::臨時ARP表
set "ARPList=%temp%\ARP"
::臨時主機名錶
set "NameList=%temp%\Names"
::臨時變數檔案
set "TMP=%temp%\TMPV"
::清理臨時檔案
(
del "%IPList%"
del "%ARPList%"
del "%NameList%"
del "%TMP%"
)2>nul 1>nul
echo.┌─────────┰────────┰────────┐>"%FName%"
echo.│ Mac Address ┃ IP Address ┃ Machine Name │>>"%FName%"
echo.┝━━━━━━━━━╋━━━━━━━━╋━━━━━━━━┥>>"%FName%"
::獲取可達IP
arp -d 2>nul 1>nul
for /f "delims=. tokens=1-4" %%i in ("%Range%") do (
set "SGMNT=%%i.%%j.%%k."
for /f "delims=- tokens=1,2" %%A in ("%%l") do (
for /l %%E in (%%A,1,%%B) do (
set "IP=!SGMNT!%%E "
echo.Pinging !IP:~,15! with %Bytes%-byte data. . .
(ping -n 1 -w %Timeout% -l %Bytes% !IP!>nul)&&(echo.!IP!>>"%IPList%")
)
::獲取機器名和Mac地址
arp -a>"%ARPList%"
nbtstat -R>nul
for /f "tokens=*" %%i in (%IPList%) do (
nbtstat -a %%i>"%NameList%"
find "=" "%NameList%">nul && (
type "%NameList%"|find /V "GROUP"|find "">"%TMP%"
for /f "delims=
type "%NameList%"|find "=">"%TMP%"
for /f "delims== tokens=2*" %%A in (%TMP%) do set "Mac=%%A"
) || (
for /f "tokens=2 usebackq" %%A in (`find " %%i " "%ARPList%"`) do set "Mac=%%A"
set "Mac=!Mac: =! "
set "Mac=!Mac:~,17! "
set "IP=%%i "
set "IP=!IP:~,16!"
set "Name=!Name! "
set "Name=!Name:~,16!"
echo.│!Mac!┃!IP!┃!Name!│>>"%FName%"
echo.└─────────┸────────┸────────┘>>"%FName%"
echo.%DATE% %TIME%>>"%FName%"
start notepad "%FName%"
@ECHO OFF & setLocal enableDelayedExpansion
::設定網段
set Range=10.10.1.1-254
::設定超時時間(毫秒)
set Timeout=5
::設定資料大小(位元組)
set Bytes=1
::設定輸出檔名
set FName=%date:~,4%%date:~5,2%%date:~8,2%%time::=%
set FName=%FName: =0%
set "FName=線上IP_%FName:.=%.txt"
::臨時IP列表
set "IPList=%temp%\IPs"
::臨時ARP表
set "ARPList=%temp%\ARP"
::臨時主機名錶
set "NameList=%temp%\Names"
::臨時變數檔案
set "TMP=%temp%\TMPV"
::清理臨時檔案
(
del "%IPList%"
del "%ARPList%"
del "%NameList%"
del "%TMP%"
)2>nul 1>nul
echo.┌─────────┰────────┰────────┐>"%FName%"
echo.│ Mac Address ┃ IP Address ┃ Machine Name │>>"%FName%"
echo.┝━━━━━━━━━╋━━━━━━━━╋━━━━━━━━┥>>"%FName%"
::獲取可達IP
arp -d 2>nul 1>nul
for /f "delims=. tokens=1-4" %%i in ("%Range%") do (
set "SGMNT=%%i.%%j.%%k."
(
for /f "delims=- tokens=1,2" %%A in ("%%l") do (
(
for /l %%E in (%%A,1,%%B) do (
set "IP=!SGMNT!%%E "
echo.Pinging !IP:~,15! with %Bytes%-byte data. . .
(ping -n 1 -w %Timeout% -l %Bytes% !IP!>nul)&&(echo.!IP!>>"%IPList%")
)
)
)
)
)
::獲取機器名和Mac地址
arp -a>"%ARPList%"
nbtstat -R>nul
for /f "tokens=*" %%i in (%IPList%) do (
nbtstat -a %%i>"%NameList%"
find "=" "%NameList%">nul && (
type "%NameList%"|find /V "GROUP"|find "">"%TMP%"
for /f "delims=
type "%NameList%"|find "=">"%TMP%"
for /f "delims== tokens=2*" %%A in (%TMP%) do set "Mac=%%A"
) || (
for /f "tokens=2 usebackq" %%A in (`find " %%i " "%ARPList%"`) do set "Mac=%%A"
)
set "Mac=!Mac: =! "
set "Mac=!Mac:~,17! "
set "IP=%%i "
set "IP=!IP:~,16!"
set "Name=!Name! "
set "Name=!Name:~,16!"
echo.│!Mac!┃!IP!┃!Name!│>>"%FName%"
)
echo.└─────────┸────────┸────────┘>>"%FName%"
echo.%DATE% %TIME%>>"%FName%"
del "%IPList%"
del "%ARPList%"
del "%NameList%"
del "%TMP%"
start notepad "%FName%"