|
Low level functions examples
Resolving host name and IP address
This example consists of two files: lookup.htm and lookup.asp.
First file is usual short HTML document with form. Using that form you can
enter the Internet host name or address in the input field (for example, www.microsoft.com).
The second file is ASP script that does the following:
- If you specified the host internet address, the script gets you host name.
- If you specified the host name, the script gets you host intrnet address.
<HEAD>
<TITLE>ShotIp: The host name and address lookup example</TITLE>
</HEAD>
<BODY bgcolor=#ffffff>
<H1>Example: The ASP script looking up for
Internet host name and address</H1>
<FORM action="lookup.asp" method=POST>
<TABLE><TR>
<TD valign=right>Host name or address:</TD>
<TD><INPUT name="host"></TD></TR></TABLE>
<BR><INPUT type="Submit">
</FORM>
</BODY>
|
<HEAD>
<TITLE>The query results</TITLE>
</HEAD>
<BODY bgcolor=#ffffff>
<H1>The result of host lookup</H1>
<%
Set tcpip=CreateObject("SHOTIP.Connection")
'Commented for unregistered version
'tcpip.Timeout=30
Main()
Sub Main()
name=tcpip.LookupHost(Request.Form("host"))
if name<>"" then
Response.Write name
else
Response.Write "Could not resolve host name/addr."
end if
End Sub
%>
</BODY>
|
VBS example: HTTP downloading of binary files
NOTE: the goal of this example can more easy be reached by using of HttpConnection object. However, this example
shows usage of all low level methods.
What this VB script does.
The HTTPGET.VBS script lets you download files from remote hosts to your local disk via HTTP.
The script accepts the full URL of the file as parameter. To use the script
you should run it from command line using cscript from Windows Scripting
Host (part of Option Pack 4 for NT). For example:
cscript httpget.vbs http://www.thathost.com/path/to/file/filename.jpg
You can use other scripting engines as well instead of VBScript (VBA, for example) after some modifications.
The script parses URL, connects to port 80 of remote host and send the GET
HTTP request.
The files are downloaded into specified location. The default directory is
"c:\". To change this setting to other one, for example, to "c:\downloads",
change the "download_to" variable in the beginning of HTTPGET.VBS file.
Reconnection
If you download a big file and the connection with remote host is bad, the
connection can be terminated before the downloading will be finished. In that
case the script will immediately try to connect again and download the rest of the file using the Range
HTTP request header. If WWW server supports this feature the script will append
the necessary data. If WWW server does not support the Range header, the
script will try to get the whole file again.
|
|
|