I love to share with you my work which based on other people's work although much of it are from my own creativity.
When I said "report", I really mean so. It is a formatted HTML page.
And what I am referring to as "network" can be WAN or LAN, external IP (or host name) or internal IP (or computer name).
I built my own Network Diagnostic Report generator!
It serves my company purpose, as an I.T. Executive, I need such a report that tell me which shops are offline and which shops are not, actually more than that.
First, you need tool to ping a particular port.
PAPING - a Google project, comes handy as a freeware.
Next, for the generation of formatted HTML page as final report, we need:
CSVFIX - a SourceForge project, comes handy as a freeware, too.
CSVFILEVIEW - a CSV to HTML converter (and viewer) from NirSoft, also a freeware itself.
FART - Find And Replace Text, a command-line tool that tweak a bit the HTML output generated by the converter.
My code divided into two sections:
Quote
@echo off
set fnm=HOSTNAME.txt
set lnm=RESULT.txt
del %lnm%
if exist HOSTNAME.txt set fnm=HOSTNAME.txt
if exist C:\NT\HOSTNAME.txt set fnm=C:\NT\HOSTNAME.txt
if exist %fnm% goto SALES
echo.
echo Cannot find %fnm%
echo.
Pause
goto :EOF
:SALES
for /f "tokens=1,2 delims=," %%i in (%fnm%) do call :SUB_1 %%i %%j
goto :DVR
:SUB_1
echo Testing %1 for SALES
set state=ONLINE
paping %1 -p 3050 -c 1
if errorlevel 1 set state=**OFFLINE**
echo %2,3050,%state% >> %lnm%
goto :EOF
:DVR
for /f "tokens=1,2 delims=," %%i in (%fnm%) do call :SUB_2 %%i %%j
goto :VNC
:SUB_2
echo Testing %1 for DVR
set state=ONLINE
paping %1 -p 9696 -c 1
if errorlevel 1 set state=**OFFLINE**
echo %2,9696,%state% >> %lnm%
goto :EOF
:VNC
for /f "tokens=1,2 delims=," %%i in (%fnm%) do call :SUB_3 %%i %%j
goto :GEN
:SUB_3
echo Testing %1 for VNC
set state=ONLINE
paping %1 -p 5900 -c 1
if errorlevel 1 set state=**OFFLINE**
echo %2,5900,%state% >> %lnm%
goto :EOF
:GEN
GENERATE.BAT
I actually need to scan three different ports, 3050 (Firebird) and 5900 (RealVNC) related to PC, while 9696 related to CCTV recorder.
Sample of HOSTNAME.txt are:
Quote
"subdomain1.dyndns.org","New York"
"subdomain2.dyndns.org","London"
"subdomain3.dlinkddns.com","Paris"
The C:\NT\HOSTNAME.txt has higher precedence than the HOSTNAME.txt resides in the local directory. This is optional.
The following section are generation and formatting of HTML page as the final report:
Quote
@echo off
del RESULT_5.txt
del RESULT_4.txt
del RESULT_3.txt
del RESULT_2.txt
del RESULT_U.htm
del RESULT.htm
del TIMESTAMP.txt
csvfix sort -f 1:AS,2:AN -ibl -o RESULT_2.txt RESULT.txt
csvfix flatten -k 1 -o RESULT_3.txt RESULT_2.txt
csvfix sequence -n 1 -i 1 -f 1 -o RESULT_4.txt RESULT_3.txt
echo %date% %time% > TIMESTAMP.txt
copy RESULT_4.txt+TIMESTAMP.txt RESULT_5.txt
csvfileview /load RESULT_5.txt /shtml RESULT_U.htm
type RESULT_U.htm>RESULT.htm
fart RESULT.htm "Text File Report" "Network Diagnostic Report - NT Shop Sdn Bhd"
fart RESULT.htm "www.nirsoft.net/" "www.ntshop.com.my"
fart RESULT.htm "Created by using" " "
fart RESULT.htm "CSVFileView" "www.ntshop.com.my"
fart RESULT.htm "Column 1" "No."
fart RESULT.htm "Column 2" "Store"
fart RESULT.htm "Column 3" "Sales"
fart RESULT.htm "Column 4" "Status"
fart RESULT.htm "Column 5" "VNC"
fart RESULT.htm "Column 6" "Status"
fart RESULT.htm "Column 7" "DVR"
fart RESULT.htm "Column 8" "Status"
del RESULT_5.txt
del RESULT_4.txt
del RESULT_3.txt
del RESULT_2.txt
del RESULT_U.htm
del TIMESTAMP.txt
start RESULT.htm
As you might already noticed, CSVFIX is very powerful command-line tool for handling CSV files.
I use it to sort hostname ascendingly, then port number descendingly.
I even use it to combine multiple rows that having the same hostname but just different port number and ping result.
Finally, I use it to add sequential number to the first column of the CSV file.
Then, I generated a timestamp to another file (to be concatenated to the bottom of the report).
CSVFILEVIEW is used to convert the CSV file to HTML file, in non-verbose mode.
Next, I save the HTML file from Unicode format to ANSI format (or otherwise FART cannot search and replace double-byte strings).
And now, I use FART to replace the original name and title of the HTML file with my company name and report title.
Show it.
All these are done in a command-line window.
I have only tested them on Windows 7. I will test them on Windows XP tomorrow in office.
Please let me know if there is any defects.
And feel free to share it.
Attached File(s)
-
RESULT.htm (8.62K)
Number of downloads: 7



Help

Back to top










