Vbscript Ip File Lab

Only available on StudyMode
  • Download(s) : 116
  • Published : February 17, 2013
Open Document
Text Preview
VBScript IP File Lab

Objective
In this lab, students will complete the following objectives. * Create a VBScript program using NotePad++.
* Write a two-dimensional array of IP addresses to a text file. * Read the IP Addresses text file into a script.
* Append new Room/PC/IP address data to the text file.
* Use the object Scripting.FileSystemObject.

Element K Network Connections

For this lab, we will only need to connect to vlab-PC1. The computer vlab-PC1 is the computer on the left side while vlab-PC2 is on the right. If you leave the cursor on the PC icon for a few seconds, a tool-tip message will appear indicating the hostname of the PC. Open vlab-PC1 and log in as Administrator with the password password.

Lab Overview
We are going to start our lab with the same two-dimensional array of IP addresses. Rather than accessing this array of IP address using the room and computer index values, we are going to write the array of IP addresses to a Text file named IP_Addresses.csv where each line of the file will contain the Comma Separated Values (CSV) for room#,computer#,IP_Address. We will then write a separate VBScript program that will append four new lines of data that will represent the four computers in the new room 106 to the IP_Addresses.csv file. Lastly, we will open and read the newly appended IP_Addresses.csv and display it contents in a meaningful way.

Note: All captures must be text only—DO NOT capture the NotePad++ application window or the command prompt window. Use copy and paste of text only.

Task 1: Download and Open IP_ArrayFile_start.vbs in NotePad++

* Open NotePad++ and from the menu, select File/Open. Open the file IP_File_start.vbs in the C:\Scripts directory. If you do not see this file, you can download it and extract it from the eCollege Doc Sharing file IP_File_start.zip.

* Modify the Programmer Header as needed and Save As the VBScript file as IP_FileWrite.vbs.

* The line dim ipAddress(5,3) declare 6x4 two-dimensional array. The 5 and 3 give the maximum index value. Since indices always start at 0, this is a 6x4 array.

* The lines that follow initialize the array locations with IP addresses. The first index (0..5) represents the rooms 100 through 105. The second index (0..3) represent the four computers in each room.

* The IP address of the third computer in room 104 can be found in the array element or component ipAddress(4,2). This value is “192.168.10.45”. Look at the array carefully to determine the meaning of the index values.

Note: If you need to upload a file into the C:\Scripts directory on vlab-PC1 or download a file from the vlab-PC1 C:\Scripts file, open Windows Explorer (E). As you can see on the right, your local computer drives (in this case, the C: and D: ) are mapped to file copy and paste (or drag and drop) easy to accomplish.

Task 2: Add the Code to Write the Array Data to a File
Pseudocode| Comments|
Define the following constantsREAD = 1, WRITE = 2, APPEND = 8, ASCII = 0Define the variable fileName and initialize it to “IP_Addresses.csv” Define the variable ipAddrStr and initialize it to “”Set fso to the “ScriptingFileSystemObject” using CreateObject Set ipFileObj = fso.CreateTextFile(filename,True,ASCII)For room = 0 to 5 For computer = 0 to 3 ipAddrStr = CStr(room+100) & "," & CStr(computer+1) & "," & ipAddress(room,computer) & vbCrLf Use ipFileObj to Write(IpAddrStr) NextNext Close the fileSet ipFileObj = fso.OpenTextFile(fileName,READ,ASCII)WScript.Echo ipFileObj.ReadAllipFileObj.Close | Named constants should be all caps and the Const prefix should be used to differentiate it from a variable whose value can change.fileName is a variable that contains the name of the file we will write.ipAddrStr will be used later to store individual records that we will write to the file “C:\Scripts\IP_Addresses.csv”.You always need to use...
tracking img