Wednesday, December 4, 2019

VBScript IP File Lab Essay Sample free essay sample

AimIn this lab. pupils will finish the undermentioned aims. * Create a VBScript plan utilizing NotePad++ .* Write a planar array of IP addresses to a text file. * Read the IP Addresses text file into a book.* Append new Room/PC/IP reference informations to the text file.* Use the object Scripting. FileSystemObject. Element K Network Connections For this lab. we will merely necessitate to link to vlab-PC1. The computing machine vlab-PC1 is the computing machine on the left side while vlab-PC2 is on the right. If you leave the pointer on the Personal computer icon for a few seconds. a tool-tip message will look bespeaking the hostname of the Personal computer. Open vlab-PC1 and log in as Administrator with the watchword watchword. Lab OverviewWe are traveling to get down our lab with the same planar array of IP references. Rather than accessing this array of IP reference utilizing the room and computing machine index values. We will write a custom essay sample on VBScript IP File Lab Essay Sample or any similar topic specifically for you Do Not WasteYour Time HIRE WRITER Only 13.90 / page we are traveling to compose the array of IP addresses to a Text file named IP_Addresses. csv where each line of the file will incorporate the Comma Separated Values ( CSV ) for room # . computing machine # . IP_Address. We will so compose a separate VBScript plan that will add on four new lines of informations that will stand for the four computing machines in the new room 106 to the IP_Addresses. csv file. Last. we will open and read the freshly appended IP_Addresses. csv and expose it contents in a meaningful manner. Note: All gaining controls must be text only—DO NOT capture the NotePad++ application window or the bid prompt window. Use transcript and paste of text merely. Undertaking 1: Download and Open IP_ArrayFile_start. vbs in NotePad++ * Open NotePad++ and from the bill of fare. choice File/Open. Open the fileIP_File_start. vbs in the C: Scripts directory. If you do non see this file. you can download it and pull out it from the eCollege Doc Sharing file IP_File_start. nothing. * Modify the Programmer Header as needed and Save As the VBScript file as IP_FileWrite. vbs. * The line dim ipAddress ( 5. 3 ) declare 6?4 planar array. The 5 and 3 give the maximal index value. Since indices ever start at 0. this is a 6?4 array. * The lines that follow initialise the array locations with IP references. The first index ( 0. . 5 ) represents the suites 100 through 105. The 2nd index ( 0. . 3 ) represent the four computing machines in each room. * The IP reference of the 3rd computing machine in room 104 can be found in the array component or constituent ipAddress ( 4. 2 ) . This value is â€Å"192. 168. 10. 45† . Look at the array carefully to find the significance 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. unfastened Windows Explorer ( E ) . As you can see on the right. your local computing machine thrusts ( in this instance. the C: and D: ) are mapped to register transcript and paste ( or retarding force and bead ) easy to carry through. Undertaking 2: Add the Code to Write the Array Data to a FilePseudocode| Comments|Specify the undermentioned constantsREAD = 1. WRITE = 2. APPEND = 8. ASCII = 0Define the variable filename and initialise it to â€Å"IP_Addresses. csv† Define the variable ipAddrStr and initialise it to â€Å"†Set fso to the â€Å"ScriptingFileSystemObject† utilizing CreateObject Set ipFileObj = fso. CreateTextFile ( file name. True. ASCII ) For room = 0 to 5 For computing machine = 0 to 3 ipAddrStr = CStr ( room+100 ) A ; â€Å" . † A ; CStr ( computer+1 ) A ; â€Å" . † A ; ipAddress ( room. computing machine ) A ; vbCrLf Use ipFileObj to Write ( IpAddrStr ) NextNext Close the fileSet ipFileObj = fso. OpenTextFile ( filename. READ. ASCII ) WScript. Echo ipFileObj. ReadAllipFileObj. Close | Named invariables should be all caps and the Const prefix should be used to distinguish it from a variable whose value can alter. filename is a variable that contains the nam e of the file we will compose. ipAddrStr will be used subsequently to hive away single records that we will compose to the file â€Å"C: ScriptsIP_Addresses. csv† . You ever need to utilize â€Å"ScriptingFileSystemObject† to read. compose. or append files. The CreateTextFile method has one required statement and two optional statements. The first statement value is the file name as twine invariable or variable. The statement set to True agencies we will over-write the file if it exists. The 3rd statement specifies the textfile format -1=Unicode. 0=ASCII. 1= system default format. Note the usage of the variable file name. Once ipFileObj is linked to a file. it can be used merely like WScript. StdOut. You can utilize the Write ( ) . WriteLine ( ) . and WriteBlankLines ( ) methods. Nested For cringles are used to entree the planar array of IP references. The outside cringle specifies the room 0. . 5 ( stand foring suites 100. . 105 ) and the inside cringle specifies the computing machine 0. . 3 ( stand foring computing machines 1. . 4 ) . In the first base on balls through the cringle when room = 0 and computing machine = 0. ipAddrStr is set to the value†100. 1. 192. 168. 10. 11† . Close the IP_Addresses. csv file utilizing ip FileObj. Near Here we are opening the IP_Addresses. csv file and exposing its contents to verify the File Creation and data format. . | Add the codification indicated by the pseudocode shown below to compose the Array to a text file. Actual codification and identifiers for variables and methods within the pseudocode will be in bold fount. Carefully read the remarks to the right of the pseudocodewill be in italics. * Save your plan with S. * Press and enter cscript FileWrite. vbs. Click OK to get down your book run. Your book will run in a docked Console window in NotePad++ as shown below. * Another option for running this plan is to open a Windows Command Prompt ( CLI ) . alteration directory to the C: Scripts folder and run the plan by come ining the bid cscript IP_FileWrite. vbs. * Execute the dir * . csv bid to verify the being of the IP_Addresses. csv file. * If your tally has any mistakes or your file does non incorporate the informations shown above. debug your plan and re-run it until you have the right consequences. When you have achieved the right consequences. transcript and glue your IP_FileWrite. vbs plan from NotePad++ into the specified textbox in your lab-report papers. Besides copy the Windows bid prompt tally and file confirmation into the specified textbox into your lab-report papers. | Undertaking 3: Make the IP_AppendRead. vbs Plan The IP_AppendRead. vbs plan will make informations for a new room with four computing machines with assigned IP references. The plan will add on these four records ( one for each IP reference ) to the IP_Addresses. csv file. Then the plan will open the IP_Addresses. csv file and expose the contents of the file in a 1 record per line descriptive format. The new room records that were appended should be displayed. * Open NotePad++ and make a new file called IP_AppendRead. vbs. Salvage this new book file in the C: Scripts directory. Do non copy and glue any codification from your IP_WriteFile. vbs plan. This plan should be written from abrasion. * Add the codification indicated by the pseudocode shown below to add on the new room informations to IP_Addresses. csv. Actual codification and identifiers for variables and methods within the pseudocode will be in bold fount. Carefully read the remarks to the right of the pseudocode ; they will be in italics. Pseudocode| Comments|Add an appropriate coder heading Specify the undermentioned constantsREAD = 1. WRITE = 2. APPEND = 8. ASCII =0Define the variable filename and initialise it to â€Å"IP_Addresses. csv†Define the variable ipAddrStr and initialise it to â€Å"†Define newRoom and initial it to â€Å"106†Define comp1_IP and initialise it to â€Å"192. 168. 10. 59†Define comp2_IP and initialise it to â€Å"192. 168. 10. 60†Define comp3_IP and initialise it to â€Å"192. 168. 10. 61†Define comp4_IP and initialise it to â€Å"192. 168. 10. 62†Set fso to the object â€Å"Scripting. FileSystemObject† | Named invariables should be all caps and the const prefix should be used to distinguish it from a variable whose value can alter. filename is a variable that contains the name of the file we will compose. ipAddrStr will be used to construct the record twine that will be written to the file â€Å"C: ScriptsIP_Addresses. csv† . The variables newRoom. comp1_IP. comp2_IP. comp3_IP. and comp4_IP are set to values that represent a new room ( 106 ) that contains four computing machines with specific IP references. Use the CreateObject ( ) method to Set fso as an object of type: â€Å"Scripting. FileSystemObject† . | Pseudocode| Comments| ipAddrStr = _ newRoom A ; â€Å" . 1. † A ; comp1_IP A ; vbCrLf A ; _ newRoom A ; â€Å" . 2. † A ; comp2_IP A ; vbCrLf A ; _ newRoom A ; â€Å" . 3. † A ; comp3_IP A ; vbCrLf A ; _ newRoom A ; â€Å" . 4. † A ; comp4_IP A ; vbCrLfIf file identified by filename does non be Then Beep Speaker Twice Display Message:â€Å"File Does Not Exist! ! ! † A ; newline A ; â€Å"You Must Create the File Before You can Read the File! ! † Quit ProgramEnd IfSet File object ipFileObj utilizing fso. OpenTextFile ( ) make certain file is set APPEND and ASCII format Use ipFileObj object to add on ipAddrStr to stop of the file identified by fileNameClose the file| ipAddrStr is set to a value that represents the four Personal computers in the new room 106. Note the usage of the Line continuance character _ . Files can be checked for being utilizing the fso method FileExists ( ) . The NOT Boolean operator may be utile here. If C: ScriptsIP_Addresses. csv does non be. Beep talker twice and expose mistake message. Exit the plan with WScript. Quit. Set ipAddrFile to register filename for APPEND and ASCII. Set ipFileObj =fso. OpenTextFile ( filename. APPEND. ASCII ) Once ipFileObj is linked to a file. it can be used merely like WScript. StdOut. You can utilize the Write ( ) . WriteLine ( ) . and WriteBlankLines ( ) methods. Use the Close method of ipFileObj| * At this point. Salvage your IP_AppendRead. vbs book utilizing S. Run your plan in NotePad++ with come ining cscript IP_AppendRead. vbs or from the Windows Command Prompt in the C: Scripts directory. * After running your plan. utilize the type IP_Addresses. csv bid from the Windows Command Prompt in C: Script or open the file in NotePad++ to verify that the new informations for room 106 has been written. Degree centigrades: Scripts gt ; type IP_Addresses. csv100. 1. 192. 168. 10. 11100. 2. 192. 168. 10. 12 Important Note: After you have verified that the room 106 information has been 100. 3. 192. 168. 10. 13sucessfully written to IP_Addresses. csv. re-run your antecedently written 100. 4. 192. 168. 10. 14IP_FileWrite. vbs plan to reconstruct the original informations. 101. 1. 192. 168. 10. 19 101. 2. 192. 168. 10. 20101. 3. 192. 168. 10. 21101. 4. 192. 168. 10. 22102. 1. 192. 168. 10. 27102. 2. 192. 168. 10. 28102. 3. 192. 168. 10. 29102. 4. 192. 168. 10. 30103. 1. 192. 168. 10. 35103. 2. 192. 168. 10. 36103. 3. 192. 168. 10. 37103. 4. 192. 168. 10. 38104. 1. 192. 168. 10. 43104. 2. 192. 168. 10. 44104. 3. 192. 168. 10. 45104. 4. 192. 168. 10. 46105. 1. 192. 168. 10. 51105. 2. 192. 168. 10. 52105. 3. 192. 168. 10. 53105. 4. 192. 168. 10. 54106. 1. 192. 168. 10. 59Return to your plan in NotePad++ and finish composing the balance of your plan 106. 2. 192. 168. 10. 60using the pseudocode found on the following page. 106. 3. 192. 168. 10. 61106. 4. 192. 168. 10. 62 The pseudocode shown below will the stairss needed to open and read the appended file IP_Addresses. curriculum vitae and expose the information in the format †The IP Address in Room † room # † for Computer † computing machine # † is † ipAddress Pseudocode| Comments|Using fso. OpenTextFile ( ) . make the ipFileObj object that has opened file name for Reading in ASCII format. Make Until ipFileObj is at EndOfStream room = ipFileObject. Read 3 characters ipFileObj. Skip 1 character computing machine = ipFileObj. Read 1 character ipFileObj. Skip 1 character ipAddress = ipFileObj. Read 13 characters ipAddrFile. Skip newline Display Message: â€Å"The IP Address in Room † A ; room A ; † for Computer â€Å" A ; computing machine A ; † is † A ; ipAddressEnd LoopClose File| Set ipFileObj to open filename for Reading in ASCII format. Set ipFileObj = fso. OpenTextFile ( filename. READ. ASCII ) Once ipFileObj is linked to a file. it can be used merely like WScript. StdIn. You can utilize the Read ( ) . ReadLine ( ) . Skip ( ) and SkipLine methods. The Do/Until cringle will expose all of the IP_Addresses. csv records including the room 106 records that were added. Use the Close method of ipFileObj where room # . computing machine # and ipAddress are values read from the IP_Addresses. csv file. Undertaking 4: Finish Program and Run it Showing Error-Handling * Finish composing your plan and salvage it. Run your plan utilizing in NotePad++ or open a Windows Command Prompt and run it from the C: Scripts directory. Your tally should look like the undermentioned. Note the highlighted records in the tally. These are the appended records for room 106. * If you did non acquire the consequences shown on the right. you will necessitate to debug your plan and run it once more until you get these consequences. To take duplcate records or reconstruct the original informations in the IP_Addresses. csv file. re-run the IP_FileWrite. vbs plan. When you have achieved the right consequences transcript and glue your IP_AppendRead. vbs plan from NotePad++ into the specified textbox in your lab-report papers. Besides copy the Run run into the specified textbox in your lab-report papers. | The. csv extension that we used on our IP_Addresses file indicates a Comma Separated Value format. This sort of file can be opened by Microsoft Excel and Microsoft Access. The file could be easy edited utilizing Excel or even made into a database in Access by adding some field names. Below is our IP_Addresses. csv file opened in Excel ( left ) and Access ( right ) .

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.