-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsclient.ps1
More file actions
56 lines (52 loc) · 1.4 KB
/
Copy pathpsclient.ps1
File metadata and controls
56 lines (52 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#------------------------------------------------------------
# Argument
#------------------------------------------------------------
$addr = $args[0]
$port = $args[1]
$cmd = $args[2]
#------------------------------------------------------------
# Functions
#------------------------------------------------------------
#
# return: line data for success
# $null for failure
#
Function readLine($rd){
try {
$line = $rd.readLine()
}catch{
$line = $null
}
return $line
}
#
# return: $true for success
# $false for failure
#
Function writeLine($wd, $line){
$stat = $true
try {
$wd.writeLine($line)
$wd.Flush()
}catch{
$stat = $false
}
return $stat
}
#------------------------------------------------------------
# Main procedure
#------------------------------------------------------------
$client = New-Object System.Net.Sockets.TcpClient ($addr, $port)
$stream = $client.GetStream()
$reader = New-Object IO.StreamReader($stream,[Text.Encoding]::Default)
$writer = New-Object IO.StreamWriter($stream,[Text.Encoding]::Default)
$stat = writeLine $writer $cmd
$line = readLine $reader
while ($line -ne $null -and $line -ne "__END__"){
$line -replace "^:", ""
$line = readLine $reader
}
$writer.Close()
$reader.Close()
$stream.Close()
$client.Close()