class Nastika::UDP
This class provides way to talk to the host over UDP
.
Attributes
connected[RW]
connection[RW]
host[RW]
payload[RW]
port[RW]
Public Class Methods
new(host=nil, port=nil, payload=Nastika::Constants::DEFAULT_PAYLOAD)
click to toggle source
Initializes the Nastika::UDP
object. WARNING: Does not connect to host automatically. Params:
host
-
Hostname of the target.
port
-
Port on host to connect to.
payload
-
The payload to send to host.
# File lib/nastika/udp.rb, line 20 def initialize(host=nil, port=nil, payload=Nastika::Constants::DEFAULT_PAYLOAD) self.host = host self.port = port self.payload = payload self.connected = false unless self.host.nil? & self.port.nil? self.connection = Base.new(Nastika::Constants::UDP) self.connection.host = self.host self.connection.port = self.port self.connection.payload = payload end end
Public Instance Methods
close()
click to toggle source
Closes the connection
# File lib/nastika/udp.rb, line 61 def close if self.connected self.connection.quit self.connected = false else raise RuntimeError, "We're not connected yet." end end
connect()
click to toggle source
Connects to the host over UDP
# File lib/nastika/udp.rb, line 35 def connect if ! self.connected begin self.connection.connect self.connected = true self.connection rescue SocketError raise ArgumentError, "Cannot connect to #{self.host}:#{self.port}" end else raise RuntimeError, "We're already connected." end end
send(paylaod=self.payload, bytes=Nastika::Constants::DEFAULT_BYTES)
click to toggle source
Sends the payload to the host and returns the read bytes. If a payload is passed as argument, send that else sends the payload set during initialization. Params:
payload
-
Default is “GET / HTTP/1.0rnrn” or whatever was initialized.
bytes
-
Amount of byted to read from host after sending request.
# File lib/nastika/udp.rb, line 55 def send(paylaod=self.payload, bytes=Nastika::Constants::DEFAULT_BYTES) self.connection.send(payload) self.connection.get(Nastika::Constants::DEFAULT_BYTES) end