FlierMate Posted December 2, 2012 Posted December 2, 2012 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 offset fnm=HOSTNAME.txtset lnm=RESULT.txtdel %lnm%if exist HOSTNAME.txt set fnm=HOSTNAME.txtif exist C:\NT\HOSTNAME.txt set fnm=C:\NT\HOSTNAME.txtif exist %fnm% goto SALESecho.echo Cannot find %fnm%echo.Pausegoto :EOF:SALESfor /f "tokens=1,2 delims=," %%i in (%fnm%) do call :SUB_1 %%i %%jgoto :DVR:SUB_1echo Testing %1 for SALESset state=ONLINEpaping %1 -p 3050 -c 1 if errorlevel 1 set state=**OFFLINE**echo %2,3050,%state% >> %lnm%goto :EOF:DVRfor /f "tokens=1,2 delims=," %%i in (%fnm%) do call :SUB_2 %%i %%jgoto :VNC:SUB_2echo Testing %1 for DVRset state=ONLINEpaping %1 -p 9696 -c 1 if errorlevel 1 set state=**OFFLINE**echo %2,9696,%state% >> %lnm%goto :EOF:VNCfor /f "tokens=1,2 delims=," %%i in (%fnm%) do call :SUB_3 %%i %%jgoto :GEN:SUB_3echo Testing %1 for VNCset state=ONLINEpaping %1 -p 5900 -c 1 if errorlevel 1 set state=**OFFLINE**echo %2,5900,%state% >> %lnm%goto :EOF:GENGENERATE.BATI 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 offdel RESULT_5.txtdel RESULT_4.txtdel RESULT_3.txtdel RESULT_2.txtdel RESULT_U.htmdel RESULT.htmdel TIMESTAMP.txtcsvfix sort -f 1:AS,2:AN -ibl -o RESULT_2.txt RESULT.txtcsvfix flatten -k 1 -o RESULT_3.txt RESULT_2.txtcsvfix sequence -n 1 -i 1 -f 1 -o RESULT_4.txt RESULT_3.txtecho %date% %time% > TIMESTAMP.txtcopy RESULT_4.txt+TIMESTAMP.txt RESULT_5.txtcsvfileview /load RESULT_5.txt /shtml RESULT_U.htmtype RESULT_U.htm>RESULT.htmfart 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.txtdel RESULT_4.txtdel RESULT_3.txtdel RESULT_2.txtdel RESULT_U.htmdel TIMESTAMP.txtstart RESULT.htmAs 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. RESULT.htm
allen2 Posted December 2, 2012 Posted December 2, 2012 Look like you wanted to reinvent angry ip scanner or zenmap and both are opensource.
jaclaz Posted December 2, 2012 Posted December 2, 2012 It seems to me like an overcomplex way.The batch can be much simplified, quick example:@echo offSETLOCAL ENABLEDELAYEDEXPANSIONset fnm=HOSTNAME.txtset lnm=RESULT.txtdel %lnm%if exist HOSTNAME.txt set fnm=HOSTNAME.txtif exist C:\NT\HOSTNAME.txt set fnm=C:\NT\HOSTNAME.txtif not exist %fnm% goto :errorset SALES=3050set DVR=9696set VNC=5900FOR %%A IN ( SALES DVR VNC ) DO (ECHO %%Afor /f "tokens=1,2 delims=," %%i in (%fnm%) do call :do_paping %%i %%j %%A)::GENERATE.BATGOTO :EOF:do_paping set state=ONLINEecho Testing %1 for %3paping %1 -p !%3! -c 1if errorlevel 1 set state=**OFFLINE**echo %2,!%3!,%state% >> %lnm%goto :EOF:errorecho.echo Cannot find %fnm%echo.Pausegoto :EOFAnd most probably you can even remove the if errorlevel by using either of || or &&.jaclaz
FlierMate Posted December 3, 2012 Author Posted December 3, 2012 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.
FlierMate Posted December 3, 2012 Author Posted December 3, 2012 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.
FlierMate Posted December 3, 2012 Author Posted December 3, 2012 jaclazAnd 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.
jaclaz Posted December 3, 2012 Posted December 3, 2012 (edited) 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. 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_razorAnd:Make everything as simple as possible, but not simpler.Here :@echo offSETLOCAL ENABLEDELAYEDEXPANSIONset Htm_title=Network Diagnostic Report - NT Shop Sdn Bhdset Htm_href="http://www.ntshop.com.my"set Htm_txt=www.ntshop.com.myset fnm=HOSTNAME.txtset lnm=RESULT.HTMdel %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.txtif exist C:\NT\HOSTNAME.txt set fnm=C:\NT\HOSTNAME.txt::if not exist %fnm% goto :errorset SALES=3050set DVR=9696set VNC=5900set Counter=0for /f "tokens=1,2 delims=," %%A in (%fnm%) do (Set /A Counter+=1set Line=^<tr^>^<td bgcolor=#FFFFFF^>!Counter!^<td^>%%BFOR %%C IN ( SALES DVR VNC ) DO (call :do_paping %%A %%B %%C)ECHO !Line!>>%lnm%)(ECHO ^</table^>ECHO ^</body^>^</html^>)>>%lnm%GOTO :EOF:do_papingset state=ONLINEecho Testing %1 for %3paping.exe %1 -p !%3! -c 1 || set state=**OFFLINE**SET Line=!Line!^<td^>%state%goto :EOF:errorecho.echo Cannot find %fnm%echo.Pausegoto :EOFThe expected result is a simple .htm table, let's simply build it....jaclaz Edited December 3, 2012 by jaclaz
FlierMate Posted December 3, 2012 Author Posted December 3, 2012 Not really, there are excellent programmers in the East as well. 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_razorI 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 :...... let's simply build it....My adrenaline is rising up. 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.
net_user Posted December 6, 2012 Posted December 6, 2012 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
FlierMate Posted December 10, 2012 Author Posted December 10, 2012 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 codingThank you for your praise. But I do not quite understand your slang, did you mean scripting and coding are two different things?
net_user Posted December 10, 2012 Posted December 10, 2012 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.
FlierMate Posted December 10, 2012 Author Posted December 10, 2012 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.
net_user Posted December 10, 2012 Posted December 10, 2012 (edited) 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 numbersstart with that firstedit****once you have the vbs script configured...you have to call it from the command line via cscript Edited December 10, 2012 by net_user
FlierMate Posted December 10, 2012 Author Posted December 10, 2012 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 numbersonce you have the vbs script configured...you have to call it from the command line via cscriptThanks for the hints. It will be very useful if I found one.But why should one call a VBS script via CSCRIPT?
net_user Posted December 10, 2012 Posted December 10, 2012 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"
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now