InspectURL
M. Gallant 11/07/2000
The ability to create objects from classes in the Java API
can be used to extend the capability of Windows scripts.
Since the MS Java API is resident on any PC with IE4+ installed,
developers can leverage the capability contained therein.
The following script instantiates a Java object which contains
a method:
InspectUrl.rawUrlToFile(String urlspec, String path, boolean writerawurl)
which analyzes a web-page url and generates a file with the results.
Optionally, the raw URL content is written to a file.
To use the Java class, compile the Java source code, and place the
resultant InspectUrl.class
class file in the classpath (for example: C:\Winnt\Java\Classes)
inspecturl.vbs
'**********************************************************************************
' File: inspecturl.vbs (WSH for VBscript)
' Author: (c) Michel I. Gallant 11/07/2000
'
' Retrieves web-based url content and analyzes for tags.
' Requires Java class "InspectURL" on classpath.
' Calls Java method InspectURL.rawUrlToFile(String url, String scriptpath, boolean writerawurl)
'
' Writes text file "$$inspecturl.txt" to current script directory.
' Optionally writes "$$rawurl.txt" to current script directory.
' Opens $$inspecturl.txt using notepad.exe.
'***********************************************************************************
Option Explicit
Const ttext = "InspectURL -- M. Gallant"
Const genrawurlfile = true
Dim WshShell, fso, oJinspect, ptext
DIM url, scriptpath, inspectresult, again
ptext = "InspectURL: Captures web-page html content, " & _
"numbers lines and analyzes content for tags." & vbCrLf & _
"Generates file $$inspecturl.txt in script directory and opens with notepad.exe." & vbCrLf & _
"Optionally generates file $$rawurl.txt in script directory." & _
vbCrLf & vbCrLf & "Enter a valid URL:"
set WshShell = WScript.CreateObject("WScript.Shell")
set oJinspect = GetObject("java:InspectUrl") 'Instantiate Java object via moniker.
Set fso = CreateObject("Scripting.FileSystemObject")
scriptpath = fso.GetParentFolderName(WSCript.ScriptFullName) & "\"
Do While True
url = InputBox(ptext, ttext)
If url="" then WScript.Quit
url = Trim(url)
If NOT Instr(url, "http://")<>0 Then ' prepend http:// if not supplied with url.
url = "http://" & url
End If
inspectresult = oJinspect.rawUrlToFile(url, scriptpath, genrawurlfile) ' call the Java method.
If Instr(inspectresult, "successful")<>0 Then ' Is Java call successful, display with notepad.
WshShell.Run "notepad " & scriptpath & "$$inspecturl.txt", 1, true
End If
again = WshShell.Popup(inspectresult & vbCrLf & vbCrLf & "Continue?",0, _
ttext, vbInformation + vbYesNo)
If again = vbNo Then Exit Do
Loop
'------------------------------- End Script ---------------------------------------------
InspectUrl.java (Java class)
/* class InspectUrl
(1) Reads url into ByteArrayOutputStream (raw as received data)
(2) Writes ByteArrayOutputStream -->ByteArrayInputStream
(3) Optionally writes raw url to file "$$rawurl.txt"
(4) Reads and analyzes url content; adds line numbers and stats
on certain strings (malstrings).
(5) Writes analyzed url (adjusted EOL characters) to file "$$inspecturl.txt"
M. Gallant 11/07/2000 */
import java.io.*;
import java.net.*;
import java.util.Date;
import java.text.DateFormat;
public final class InspectUrl {
static final String newline = System.getProperty("line.separator") ;
private static final String malstrings [] = {
"