Module: Ronin::Network::UDP
- Included in:
- Net, Mixins::UDP, Support
- Defined in:
- lib/ronin/network/udp/udp.rb,
lib/ronin/network/udp/proxy.rb
Overview
Provides helper methods for using the UDP protocol.
Defined Under Namespace
Classes: Proxy
Instance Method Summary collapse
-
#udp_banner(host, port, local_host = nil, local_port = nil) {|banner| ... } ⇒ String
Reads the banner from the service running on the given host and port.
-
#udp_connect(host, port, local_host = nil, local_port = nil) {|socket| ... } ⇒ UDPSocket
Creates a new UDPSocket object connected to a given host and port.
-
#udp_connect_and_send(data, host, port, local_host = nil, local_port = nil) {|socket| ... } ⇒ UDPSocket
Creates a new UDPSocket object, connected to a given host and port.
-
#udp_open?(host, port, local_host = nil, local_port = nil, timeout = nil) ⇒ Boolean?
Tests whether a remote UDP port is open.
-
#udp_recv(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepts only one message from a client.
-
#udp_send(data, host, port, local_host = nil, local_port = nil) ⇒ true
Connects to a specified host and port, sends the given data and then closes the connection.
-
#udp_server(port = nil, host = nil) {|server| ... } ⇒ UDPServer
Creates a new UDPServer listening on a given host and port.
-
#udp_server_loop(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepting messages from clients in a loop.
-
#udp_server_session(port = nil, host = nil) {|server| ... } ⇒ nil
Creates a new temporary UDPServer listening on a given host and port.
-
#udp_session(host, port, local_host = nil, local_port = nil) {|socket| ... } ⇒ nil
Creates a new temporary UDPSocket object, connected to the given host and port.
-
#udp_single_server(port = nil, host = nil) ⇒ Object
deprecated
Deprecated.
Deprecated as of 0.5.0. Use #udp_recv instead.
Instance Method Details
#udp_banner(host, port, local_host = nil, local_port = nil) {|banner| ... } ⇒ String
Reads the banner from the service running on the given host and port.
279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ronin/network/udp/udp.rb', line 279 def (host,port,local_host=nil,local_port=nil) = nil udp_session(host,port,local_host,local_port) do |socket| = socket.readline end yield if block_given? return end |
#udp_connect(host, port, local_host = nil, local_port = nil) {|socket| ... } ⇒ UDPSocket
Creates a new UDPSocket object connected to a given host and port.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ronin/network/udp/udp.rb', line 122 def udp_connect(host,port,local_host=nil,local_port=nil) host = host.to_s port = port.to_i socket = UDPSocket.new if local_host || local_port local_host = local_host.to_s local_port = local_port.to_i socket.bind(local_host,local_port) end socket.connect(host,port) yield socket if block_given? return socket end |
#udp_connect_and_send(data, host, port, local_host = nil, local_port = nil) {|socket| ... } ⇒ UDPSocket
Creates a new UDPSocket object, connected to a given host and port. The given data will then be written to the newly created UDPSocket.
171 172 173 174 175 176 177 |
# File 'lib/ronin/network/udp/udp.rb', line 171 def udp_connect_and_send(data,host,port,local_host=nil,local_port=nil) socket = udp_connect(host,port,local_host,local_port) socket.write(data) yield socket if block_given? return socket end |
#udp_open?(host, port, local_host = nil, local_port = nil, timeout = nil) ⇒ Boolean?
Tests whether a remote UDP port is open.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ronin/network/udp/udp.rb', line 63 def udp_open?(host,port,local_host=nil,local_port=nil,timeout=nil) timeout ||= 5 begin Timeout.timeout(timeout) do udp_session(host,port,local_host,local_port) do |socket| # send an empty UDP packet, just like nmap socket.syswrite('') # send an empty UDP packet again, to elicit an Errno::ECONNREFUSED socket.syswrite('') end end return true rescue Timeout::Error return nil rescue SocketError, SystemCallError return false end end |
#udp_recv(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepts only one message from a client.
435 436 437 438 439 440 441 |
# File 'lib/ronin/network/udp/udp.rb', line 435 def udp_recv(port=nil,host=nil) udp_server_session(port,host) do |server| mesg, addrinfo = server.recvfrom(4096) yield server, [addrinfo[3], addrinfo[1]], mesg if block_given? end end |
#udp_send(data, host, port, local_host = nil, local_port = nil) ⇒ true
Connects to a specified host and port, sends the given data and then closes the connection.
245 246 247 248 249 250 251 |
# File 'lib/ronin/network/udp/udp.rb', line 245 def udp_send(data,host,port,local_host=nil,local_port=nil) udp_session(host,port,local_host,local_port) do |socket| socket.write(data) end return true end |
#udp_server(port = nil, host = nil) {|server| ... } ⇒ UDPServer
Creates a new UDPServer listening on a given host and port.
309 310 311 312 313 314 315 316 317 318 |
# File 'lib/ronin/network/udp/udp.rb', line 309 def udp_server(port=nil,host=nil) port = port.to_i host = host.to_s server = UDPSocket.new server.bind(host,port) yield server if block_given? return server end |
#udp_server_loop(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... } ⇒ nil
Creates a new UDPServer listening on a given host and port, accepting messages from clients in a loop.
388 389 390 391 392 393 394 395 396 |
# File 'lib/ronin/network/udp/udp.rb', line 388 def udp_server_loop(port=nil,host=nil) udp_server_session(port,host) do |server| loop do mesg, addrinfo = server.recvfrom(4096) yield server, [addrinfo[3], addrinfo[1]], mesg if block_given? end end end |
#udp_server_session(port = nil, host = nil) {|server| ... } ⇒ nil
Creates a new temporary UDPServer listening on a given host and port.
345 346 347 348 349 |
# File 'lib/ronin/network/udp/udp.rb', line 345 def udp_server_session(port=nil,host=nil,&block) server = udp_server(port,host,&block) server.close() return nil end |
#udp_session(host, port, local_host = nil, local_port = nil) {|socket| ... } ⇒ nil
Creates a new temporary UDPSocket object, connected to the given host and port.
206 207 208 209 210 211 212 |
# File 'lib/ronin/network/udp/udp.rb', line 206 def udp_session(host,port,local_host=nil,local_port=nil) socket = udp_connect(host,port,local_host,local_port) yield socket if block_given? socket.close return nil end |