Vous êtes sur la page 1sur 11

Student

Name

Class

Date

VBScript IP File Report


In the space provided below, copy and paste your IP_FileWrite.vbs program sourcecode. If it
doesnt fit, use the next page for the continuation of your program sourcecode.

1
COMP230_W6_IP_File_Report.docx

Revision Date: 1204

' VBScript: IP_FileWrite.vbs


' Written by:
' Date:
' class: COMP230
' Professor:
' ===================================
' This initializes a 2-dimension array
' of IP Address. The first index +100
' is the room# and the second index+1
' is the computer# in the room.
dim ipAddress(5,3)
ipAddress(0,0)="192.168.10.11"
ipAddress(0,1)="192.168.10.12"
ipAddress(0,2)="192.168.10.13"
ipAddress(0,3)="192.168.10.14"
ipAddress(1,0)="192.168.10.19"
ipAddress(1,1)="192.168.10.20"
ipAddress(1,2)="192.168.10.21"
ipAddress(1,3)="192.168.10.22"
ipAddress(2,0)="192.168.10.27"
ipAddress(2,1)="192.168.10.28"
ipAddress(2,2)="192.168.10.29"
ipAddress(2,3)="192.168.10.30"
ipAddress(3,0)="192.168.10.35"
ipAddress(3,1)="192.168.10.36"
ipAddress(3,2)="192.168.10.37"
ipAddress(3,3)="192.168.10.38"
ipAddress(4,0)="192.168.10.43"
ipAddress(4,1)="192.168.10.44"
ipAddress(4,2)="192.168.10.45"
ipAddress(4,3)="192.168.10.46"
ipAddress(5,0)="192.168.10.51"
ipAddress(5,1)="192.168.10.52"

In the space provided below to copy and paste the remainder of your IP_FileWrite.vbs
sourcecode if it did not fit in the first textbox.

3
COMP230_W6_IP_File_Report.docx

Revision Date: 1204

ipAddress(room,computer) & vbCrlf


ipAddrFile.WriteLine(ipAddrStr)
Next
Next
ipAddrFile.Close
Set ipAddrFile = fso.OpenTextFile(fileName,READ,ASCII)
WScript.Echo ipAddrFile.ReadAll
ipAddrFile.Close

In the space provided below, copy and paste the RUN of your IP_FileWrite.vbs program. Also
cscript IP_FileWrite.vbs
Process started >>>
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

100,1,192.168.10.11
100,2,192.168.10.12
100,3,192.168.10.13
100,4,192.168.10.14
101,1,192.168.10.19
101,2,192.168.10.20
101,3,192.168.10.21
101,4,192.168.10.22
102,1,192.168.10.27
102,2,192.168.10.28
102,3,192.168.10.29
102,4,192.168.10.30
103,1,192.168.10.35
103,2,192.168.10.36
103,3,192.168.10.37
103,4,192.168.10.38
104,1,192.168.10.43
104,2,192.168.10.44
104,3,192.168.10.45
104,4,192.168.10.46
105,1,192.168.10.51
105,2,192.168.10.52
105,3,192.168.10.53
105,4,192.168.10.54

<<< Process finished.


================ READY ================

C:\Scripts>Dir *.csv
Volume in drive C has no label.
Volume Serial Number is 28EB-380A

include the directory listing of all .csv files:


5
COMP230_W6_IP_File_Report.docx

Revision Date: 1204

In the space provided below, copy and paste your IP_AppendRead.vbs program
6

sourcecode. If it doesnt fit, use the next page for the continuation of your program
' VBScript: IP_AppendRead.vbs
' Written by:
' Date: 04/14/2013
' class: COMP230
' Professor: ================================
'Define Constants
ForReading = 1
ForWriting = 2
ForAppending = 8
Const ASCII = 0
'Define Program Variables
fileName="C:\Scripts\IP_Addresses.csv"
ipAddrStr = ""
'Define new room Variables
newRoom = "106"
comp1_IP = "192.168.10.59"
comp2_IP = "192.168.10.60"
comp3_IP = "192.168.10.61"
comp4_IP = "192.168.10.62"
'Define Scripting.FileSystemObject
Set fso Scripting.FileSystemObject
'Define String to represent New Room Information
ipAddrStr = _
newRoom & ",1," & comp1_IP & vbCrLf & _
newRoom & ",2," & comp2_IP & vbCrLf & _
newRoom & ",3," & comp3_IP & vbCrLf & _
newRoom & ",4," & comp4_IP & vbCrLf
'Define New Room Information to File

sourcecode.
7
COMP230_W6_IP_File_Report.docx

Revision Date: 1204

In the space provided below to copy and paste the remainder of your IP_AppendRead.vbs
sourcecode if it did not fit in the first textbox.

'Read File 1 Line per pass extracting the Room #, Computer # and IP Address
Do Until ipAddrFile.AtEndofStream = True
room = ipAddrFile.Read(3)
ipAddrFile.Skip(1)
computer = ipAddrFile.Read(1)
ipAddrFile.Skip(1)
ipAddress = ipAddrFile.Read(13)
ipAddrFile.Skip(1)
WScript.Echo "The IP Address in Room "& room &" for Computer "& computer & "is " & ipAddress
Loop
ipAddrFile.Close
Set ipAddrFile = fso.OpenTextFile(fileName,READ,ASCII)
WScript.Echo ipAddrFile.ReadAll
ipAddrFile.Close

9
COMP230_W6_IP_File_Report.docx

Revision Date: 1204

In the space provided below, copy and paste the RUN of your IP_AppendRead.vbs program.
C:\VBScripts>cscript IP_Append_Read.vbs
Microsoft Windows [Version 6.1.7601]Copyright (c) 2009 Microsoft Corporation. All rights reserved.
Copyright (C) Microsoft Corporation. All rights reserved.
The IP Address in Room 100 for Computer 1 is 192.168.10.11
The IP Address in Room 100 for Computer 2 is 192.168.10.12
The IP Address in Room 100 for Computer 3 is 192.168.10.13
The IP Address in Room 100 for Computer 4 is 192.168.10.14
The IP Address in Room 101 for Computer 1 is 192.168.10.19
The IP Address in Room 101 for Computer 2 is 192.168.10.20
The IP Address in Room 101 for Computer 3 is 192.168.10.21
The IP Address in Room 101 for Computer 4 is 192.168.10.22
The IP Address in Room 102 for Computer 1 is 192.168.10.27
The IP Address in Room 102 for Computer 2 is 192.168.10.28
The IP Address in Room 102 for Computer 3 is 192.168.10.29
The IP Address in Room 102 for Computer 4 is 192.168.10.30
The IP Address in Room 103 for Computer 1 is 192.168.10.35
The IP Address in Room 103 for Computer 2 is 192.168.10.36
The IP Address in Room 103 for Computer 3 is 192.168.10.37
The IP Address in Room 103 for Computer 4 is 192.168.10.38
The IP Address in Room 104 for Computer 1 is 192.168.10.43
The IP Address in Room 104 for Computer 2 is 192.168.10.44
The IP Address in Room 104 for Computer 3 is 192.168.10.45
The IP Address in Room 104 for Computer 4 is 192.168.10.46
The IP Address in Room 105 for Computer 1 is 192.168.10.51
The IP Address in Room 105 for Computer 2 is 192.168.10.52
The IP Address in Room 105 for Computer 3 is 192.168.10.53
The IP Address in Room 105 for Computer 4 is 192.168.10.54
The IP Address in Room 106 for Computer 1 is 192.168.10.59
The IP Address in Room 106 for Computer 2 is 192.168.10.60
The IP Address in Room 106 for Computer 3 is 192.168.10.61
The IP Address in Room 106 for Computer 4 is 192.168.10.62

10

11
COMP230_W6_IP_File_Report.docx

Revision Date: 1204