Module: Rex::Socket::Tcp

Includes:
IO::Stream, Rex::Socket
Defined in:
lib/rex/socket/tcp.rb

Overview

This class provides methods for interacting with a TCP client connection.

Defined Under Namespace

Classes: UnitTest

Instance Attribute Summary

Attributes included from IO::Stream

#abortive_close

Attributes included from Rex::Socket

#context, #ipv, #localhost, #localport, #peerhost, #peerport

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IO::Stream

#<<, #>>, #def_block_size, #def_max_loops, #def_read_loop_timeout, #def_read_timeout, #def_write_timeout, #fd, #get, #get_once, #has_read_data?, #put, #read, #timed_read, #timed_write, #write

Methods included from Rex::Socket

addr_atoc, addr_atoi, addr_aton, addr_ctoa, addr_itoa, addr_iton, addr_ntoa, addr_ntoi, bit2netmask, cidr_crack, create_ip, create_tcp, create_tcp_server, create_udp, dotted_ip?, #fd, from_sockaddr, getaddress, gethostbyname, #getlocalname, #getpeername, #getsockname, #initsock, ipv6_link_address, ipv6_mac, is_internal?, is_ipv4?, is_ipv6?, net2bitmask, portlist_to_portspec, portspec_crack, portspec_to_portlist, resolv_nbo, resolv_nbo_i, resolv_to_dotted, source_address, support_ipv6?, tcp_socket_pair, to_sockaddr, udp_socket_pair

Class Method Details

.create(hash = {}) ⇒ Object

Creates the client using the supplied hash.



23
24
25
26
# File 'lib/rex/socket/tcp.rb', line 23

def self.create(hash = {})
	hash['Proto'] = 'tcp' 
	self.create_param(Rex::Socket::Parameters.from_hash(hash))
end

.create_param(param) ⇒ Object

Wrapper around the base socket class’ creation method that automatically sets the parameter’s protocol to TCP.



32
33
34
35
# File 'lib/rex/socket/tcp.rb', line 32

def self.create_param(param)
	param.proto = 'tcp'
	Rex::Socket.create_param(param)
end

Instance Method Details

#localinfoObject

Returns local information (host + port) in host:port format.



65
66
67
68
69
# File 'lib/rex/socket/tcp.rb', line 65

def localinfo
	if (pi = getlocalname)
		return pi[1] + ':' + pi[2].to_s
	end
end

#peerinfoObject

Returns peer information (host + port) in host:port format.



56
57
58
59
60
# File 'lib/rex/socket/tcp.rb', line 56

def peerinfo
	if (pi = getpeername)
		return pi[1] + ':' + pi[2].to_s
	end
end

#shutdown(how = ::Socket::SHUT_RDWR) ⇒ Object

Calls shutdown on the TCP connection.



46
47
48
49
50
51
# File 'lib/rex/socket/tcp.rb', line 46

def shutdown(how = ::Socket::SHUT_RDWR)
	begin
		return (super(how) == 0)
	rescue ::Exception
	end
end

#type?Boolean

returns socket type

Returns:

  • (Boolean)


72
73
74
# File 'lib/rex/socket/tcp.rb', line 72

def type?
	return 'tcp'
end