VBScript IP File Lab
Objectives
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.
Lab Diagram
During your session you will have access to the following lab configuration.
Connecting to your lab
For this lab, we will only need to connect to Vlab-PC1.
· Vlab-PC1
To start simply click on the named Workstation from the device list (located on the left hand side of the screen) and click the Power on from the in tools bar. In some cases the devices may power on automatically.
During the boot up process an activity indicator will be displayed in the name tab:
· Black - Powered Off
· Orange - Working on your request
· Green - Ready to access
If the remote console is not displayed automatically in the main window (or popup) click the Connect icon located in the tools bar to start your session.
If the remote console does not appear please try the following option:
· Switch between the HTML 5 and Java client versions in the tools bar.
In the event this does not resolve your connectivity problems please visit our Help / Support pages for additional resolution options.
Task 1: Create the IP_FileWrite.vbs Program
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.
1) Open NotePad++ and from the menu, select File/Open. Open the file IP_File_start.vbs in the C:\comp230 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.
We are using the array of IP addresses that was used in Lab 4. 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.
Use SAVE AS to save this file as IP_FileWrite.vbs.
2) Add the code indicated by the pseudocode shown below to write the Array to a text file. Actual code and identifiers for variables and methods within the pseudocode will be in bold font. Carefully read the comments directly below the pseudocode.
Pseudocode
Define the following constants that will be used in your program
CONST READ = 1, WRITE = 2, APPEND = 8, ASCII = 0
We are going to create a text file with the IP address data in it. Define the variable fileName and initialize it to
“c:\comp230\IP_Addresses.csv”
Define the variable ipAddrStr and initialize it to “”
Set fso to the “Scripting.FileSystemObject” using CreateObject
We now want to create the file.
Set ipFileObj = fso.CreateTextFile(filename,True,ASCII)
We will use nested FOR loops to read the data from the two-dimensional array and store it in the text file. Each line of the file will have the room number, computer number, and ip address. Each line of data is first stored in the string variable ipAddrStr, and that data is then written to the file.