Sha256: d12e8921709cb44009d906aa408f7d486757eff76424f9b8109ae07bbae7b5d7

Contents?: true

Size: 1.3 KB

Versions: 47

Compression:

Stored size: 1.3 KB

Contents

#!/usr/bin/ruby

#
# Example script for connecting to a named pipe and performing a peek operation.
# This is used to demonstrate pipe operations.
#
# Usage: ruby pipes.rb ADDRESS PIPENAME USER PASS 1|2
#

require 'bundler/setup'
require 'ruby_smb'

address      = ARGV[0]
pipename     = ARGV[1]
username     = ARGV[2]
password     = ARGV[3]
smb_versions = ARGV[4]&.split(',') || ['1','2','3']

sock = TCPSocket.new(address, 445)
dispatcher = RubySMB::Dispatcher::Socket.new(sock)

client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
smbver = client.negotiate

if smbver == 'SMB1'
  puts "ServerMaxBuffer: #{client.server_max_buffer_size}"
else
  puts "ServerMaxRead:   #{client.server_max_read_size}"
  puts "ServerMaxWrite:  #{client.server_max_write_size}"
  puts "ServerMaxTrans:  #{client.server_max_transact_size}"
end

client.authenticate
client.tree_connect("\\\\#{address}\\IPC$")
client.create_pipe(pipename)
pipe = client.last_file

puts "Available:       #{pipe.peek_available}"
puts "PipeState:       #{pipe.peek_state}" # 3 == OK
puts "IsConnected:     #{pipe.is_connected?}"

pipe.close
puts "IsConnected:     #{pipe.is_connected?}"
client.tree_connects[-1].disconnect!
client.disconnect!

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
ruby_smb-2.0.9 examples/pipes.rb
ruby_smb-2.0.8 examples/pipes.rb
ruby_smb-2.0.7 examples/pipes.rb
ruby_smb-2.0.6 examples/pipes.rb
ruby_smb-2.0.5 examples/pipes.rb
ruby_smb-2.0.4 examples/pipes.rb
ruby_smb-2.0.3 examples/pipes.rb