Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Build Your Own Network Diagnostic Report

- - - - -

  • Please log in to reply
21 replies to this topic

#1
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

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:


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


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


@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 Files




How to remove advertisement from MSFN

#2
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,812 posts
Look like you wanted to reinvent angry ip scanner or zenmap and both are opensource.

#3
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,019 posts
  • OS:none specified
  • Country: Country Flag
It seems to me like an overcomplex way.

The batch can be much simplified, quick example:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
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 not exist %fnm% goto :error

set SALES=3050
set DVR=9696
set VNC=5900

FOR %%A IN ( SALES DVR VNC ) DO (
ECHO %%A
for /f "tokens=1,2 delims=," %%i in (%fnm%) do call :do_paping %%i %%j %%A
)

::GENERATE.BAT

GOTO :EOF

:do_paping
 set state=ONLINE
echo Testing %1 for %3
paping %1 -p !%3! -c 1
if errorlevel 1 set state=**OFFLINE**
echo %2,!%3!,%state% >> %lnm%
goto :EOF

:error
echo.
echo Cannot find %fnm%
echo.
Pause
goto :EOF

And most probably you can even remove the if errorlevel by using either of || or &&.

jaclaz

#4
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

Look like you wanted to reinvent angry ip scanner or zenmap and both are opensource.


Not really. I was Angry IP Scanner user for the past three months.

It prints IP addresses, ports and ping status with title and timestamp.
But I wanted more, a customized and yet presentable report. When I mean presentable, it does not (only) print machine-readable IP addresses, I want to have more friendlier name like store outlet location which is more human-readable. When I mean customization, I want to have my company title on top of the page, with hyperlink to my company Web site, etc.

Angry IP Scanner is great. But a command-line tool like PAPING coupled with my HTML formatting scripts will build a report tailored-specific to our needs.

Thank you for your input. I appreaciate that. I like to hear when people make replies.

#5
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

It seems to me like an overcomplex way.

The batch can be much simplified, quick example:


You're a genius, the coding skill level is way much higher than mine.

When you see my way overcomplex, and you went on to simplify it ---- it means overcomplex, too, for beginner like me. Just kidding!


Really, thank you for your input. Much of the quality software and technology are from the West on the earth, I will be continuously learning new skill from you and people like you.

:thumbup

#6
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

jaclaz


And now I realized that I made something silly: I use quotation for code snippet. I should insert as code snippet. That is why I had always been wondering why everyone of you have the initiative to make coloring to the syntax and identifier of the code.

#7
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,019 posts
  • OS:none specified
  • Country: Country Flag

Much of the quality software and technology are from the West on the earth,

Not really, there are excellent programmers in the East as well. :thumbup

What you may learn from the West (though I presume that there are similar approaches in the East) is ;) :
http://en.wikipedia.org/wiki/Occam's_razor

And:

Make everything as simple as possible, but not simpler.


Here :whistle: :
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set Htm_title=Network Diagnostic Report - NT Shop Sdn Bhd
set Htm_href="http://www.ntshop.com.my"
set Htm_txt=www.ntshop.com.my

set fnm=HOSTNAME.txt
set lnm=RESULT.HTM

del %lnm%

(
ECHO ^<^!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"^>
ECHO ^<html^>^<head^>^<title^>%Htm_title%^</title^>^</head^>
ECHO ^<body^>^<h3^>%Htm_title%^</h3^>
ECHO ^<br^>^<h4^>  ^<a href=%Htm_href% target="newwin"^>%Htm_txt%^</a^>^</h4^>^<p^>^<table border="1" cellpadding="5"^>^<tr bgcolor="E0E0E0"^>
ECHO ^<th^>No.^<th^>Store^<th^>Sales^<th^>VNC^<th^>DVR
)>>%lnm%

if exist HOSTNAME.txt set fnm=HOSTNAME.txt
if exist C:\NT\HOSTNAME.txt set fnm=C:\NT\HOSTNAME.txt

::if not exist %fnm% goto :error

set SALES=3050
set DVR=9696
set VNC=5900
set Counter=0

for /f "tokens=1,2 delims=," %%A in (%fnm%) do (
Set /A Counter+=1
set Line=^<tr^>^<td bgcolor=#FFFFFF^>!Counter!^<td^>%%B
FOR %%C IN ( SALES DVR VNC ) DO (
call :do_paping %%A %%B %%C
)
ECHO !Line!>>%lnm%

)

(
ECHO ^</table^>
ECHO ^</body^>^</html^>
)>>%lnm%

GOTO :EOF

:do_paping
set state=ONLINE
echo Testing %1 for %3
paping.exe %1 -p !%3! -c 1 || set state=**OFFLINE**
SET Line=!Line!^<td^>%state%
goto :EOF

:error
echo.
echo Cannot find %fnm%
echo.
Pause
goto :EOF

The expected result is a simple .htm table, let's simply build it....

jaclaz

Edited by jaclaz, 03 December 2012 - 09:21 AM.


#8
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

Not really, there are excellent programmers in the East as well. :thumbup


You may well mean India and China. Let alone Korea and Japan.

What you may learn from the West (though I presume that there are similar approaches in the East) is ;) :
http://en.wikipedia.org/wiki/Occam's_razor


I studied the Holy Scriptures long time ago. (Although it was originated in the Middle East)
Don't count me in as one of you because of Biblical studies, but because of my I.T. background, a loyal fan to Microsoft (only) products and services.

When the philosophy mentions "simplicity", the first thing that comes to my mind is Microsoft new logo with its Windows 8 UI. It is not funny, however, as sooner or later I will be embracing this new family of OS from Microsoft.

And:

Make everything as simple as possible, but not simpler.


Here :whistle: :
...... let's simply build it....


My adrenaline is rising up. :yes:

Tell you what, I will come back anytime in the future and take this (piece of code) for granted. THIS IS YOUR THREAD! You taught me back. :D

#9
net_user

net_user

    Advanced Member

  • Member
  • PipPipPip
  • 371 posts
  • OS:Windows 7 x86
  • Country: Country Flag
your off to a great start, but when you throw in some emailing scripts, to let you know when a site is down, then you will have stepped up your game in coding
Hex:
526573697374616e636520697320667574696c6521

A+

#10
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

your off to a great start, but when you throw in some emailing scripts, to let you know when a site is down, then you will have stepped up your game in coding


Thank you for your praise. But I do not quite understand your slang, did you mean scripting and coding are two different things?

#11
net_user

net_user

    Advanced Member

  • Member
  • PipPipPip
  • 371 posts
  • OS:Windows 7 x86
  • Country: Country Flag
what i mean is, it's one thing to make some cool batch file that does all the reporting.

it's another to create a batch file that runs all the time, and emails you when a site is down.
Hex:
526573697374616e636520697320667574696c6521

A+

#12
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

what i mean is, it's one thing to make some cool batch file that does all the reporting.

it's another to create a batch file that runs all the time, and emails you when a site is down.


Oh, I see.

E-mail part is tricky, have to specify SMTP server, login details and alternative port number, etc.

You know that I was looking for something like that, instead of e-mailing, why not texting (or sending SMS) directly to my cell phone (or handphone, mobile phone).

And, AFAIK, some modems that I have seen allow notification through e-mails if the link is down, so are some DVRs. But this is more a hardware-approach.

So, net_user do you have that very batch that does the things you told me: ping site and send notification e-mails? I am not requesting one, but just curious to know if you already have one.

#13
net_user

net_user

    Advanced Member

  • Member
  • PipPipPip
  • 371 posts
  • OS:Windows 7 x86
  • Country: Country Flag
you have to do this in steps.

first step...google vbs email script, there is a vbs script out there that can log you on to your gmail and send emails...even to cell numbers


start with that first


edit****
once you have the vbs script configured...you have to call it from the command line via cscript
;)

Edited by net_user, 10 December 2012 - 10:15 AM.

Hex:
526573697374616e636520697320667574696c6521

A+

#14
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

google vbs email script, there is a vbs script out there that can log you on to your gmail and send emails...even to cell numbers

once you have the vbs script configured...you have to call it from the command line via cscript
;)


Thanks for the hints. It will be very useful if I found one.

But why should one call a VBS script via CSCRIPT?

#15
net_user

net_user

    Advanced Member

  • Member
  • PipPipPip
  • 371 posts
  • OS:Windows 7 x86
  • Country: Country Flag
the vbs script contains all the configurations to logon to a gmail account,


you create a batch file that calls the vbs script , with a certian subject line and attach a txt file, (mail server is down in newyork)

here is a batch file....



cscript c:\sendemail.vbs 1234567890@txt.att.net "" "mailserver is down"
Hex:
526573697374616e636520697320667574696c6521

A+

#16
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

cscript c:\sendemail.vbs 1234567890@txt.att.net "" "mailserver is down"


I learnt something new about CSCRIPT.
Alright, I know what you meant right now.
Thank you.

#17
net_user

net_user

    Advanced Member

  • Member
  • PipPipPip
  • 371 posts
  • OS:Windows 7 x86
  • Country: Country Flag
once you have the emailing part down,

now you create the batch file/programming, how ever you want....to ping your stuff
when it gets a failed pinging...have it call the batch file..with the cscrpits commands in it.
Hex:
526573697374616e636520697320667574696c6521

A+

#18
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

when it gets a failed pinging...have it call the batch file..with the cscrpits commands in it.


This part I know. I have the complete picture right now.

BTW, does the script work for you well? Accurate? Do you think should increase the timeout values for slow connections (so that it won't consider it a dead host)?

#19
net_user

net_user

    Advanced Member

  • Member
  • PipPipPip
  • 371 posts
  • OS:Windows 7 x86
  • Country: Country Flag
it works perfect for me....it all depends on your situation really
how good is your vpn..ect ect...do you get any dropoffs?
how often do you need to check?

dude...you said your a I.T. Exec
ask yourself those questions and program and create to your needs
Hex:
526573697374616e636520697320667574696c6521

A+

#20
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

it works perfect for me....it all depends on your situation really


I have answered my own question, increase timeout values and return as alive host for slower connections will work in my situation.

Thank you once again.

#21
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
Here use this VBS Ping Scan that ping computer and if it reply connects to the computer and
lists some basic info.
You could do what you want without using any 3 rd party app using VBS scripting.


GunSmokingMan



#22
FlierMate

FlierMate

    End User

  • Member
  • Pip
  • 68 posts
  • OS:Windows 7 x86
  • Country: Country Flag

Here use this VBS Ping Scan that ping computer and if it reply connects to the computer and
lists some basic info.
You could do what you want without using any 3 rd party app using VBS scripting.


Dear Super Moderator, thank you for your contribution. I am not well-versed in VBS scripting, so I have no way to comment the code snippet.

BTW, I have resigned the position as I.T. Executive and am now seeking new job. It is too much to handle 40 outlets statewide.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN