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)
-
- (String) udp_banner(host, port, local_host = nil, local_port = nil) {|banner| ... }
Reads the banner from the service running on the given host and port.
-
- (UDPSocket) udp_connect(host, port, local_host = nil, local_port = nil) {|socket| ... }
Creates a new UDPSocket object connected to a given host and port.
-
- (UDPSocket) udp_connect_and_send(data, host, port, local_host = nil, local_port = nil) {|socket| ... }
Creates a new UDPSocket object, connected to a given host and port.
-
- (Boolean?) udp_open?(host, port, local_host = nil, local_port = nil, timeout = nil)
Tests whether a remote UDP port is open.
-
- (nil) udp_recv(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... }
Creates a new UDPServer listening on a given host and port, accepts only one message from a client.
-
- (true) udp_send(data, host, port, local_host = nil, local_port = nil)
Connects to a specified host and port, sends the given data and then closes the connection.
-
- (UDPServer) udp_server(port = nil, host = nil) {|server| ... }
Creates a new UDPServer listening on a given host and port.
-
- (nil) udp_server_loop(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... }
Creates a new UDPServer listening on a given host and port, accepting messages from clients in a loop.
-
- (nil) udp_server_session(port = nil, host = nil) {|server| ... }
Creates a new temporary UDPServer listening on a given host and port.
-
- (nil) udp_session(host, port, local_host = nil, local_port = nil) {|socket| ... }
Creates a new temporary UDPSocket object, connected to the given host and port.
-
- (Object) udp_single_server(port = nil, host = nil)
deprecated
Deprecated.
Deprecated as of 0.5.0. Use #udp_recv instead.
Instance Method Details
- (String) udp_banner(host, port, local_host = nil, local_port = nil) {|banner| ... }
Reads the banner from the service running on the given host and port.
277 278 279 280 281 282 283 284 285 286 |
# File 'lib/ronin/network/udp/udp.rb', line 277 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 |
- (UDPSocket) udp_connect(host, port, local_host = nil, local_port = nil) {|socket| ... }
Creates a new UDPSocket object connected to a given host and port.
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ronin/network/udp/udp.rb', line 125 def udp_connect(host,port,local_host=nil,local_port=nil) host = host.to_s port = port.to_i local_host = (local_host || '0.0.0.0').to_s local_port = local_port.to_i socket = UDPSocket.new socket.bind(local_host,local_port) if (local_host && local_port) socket.connect(host,port) yield socket if block_given? return socket end |
- (UDPSocket) udp_connect_and_send(data, host, port, local_host = nil, local_port = nil) {|socket| ... }
Creates a new UDPSocket object, connected to a given host and port. The given data will then be written to the newly created UDPSocket.
169 170 171 172 173 174 175 |
# File 'lib/ronin/network/udp/udp.rb', line 169 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 |
- (Boolean?) udp_open?(host, port, local_host = nil, local_port = nil, timeout = nil)
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 84 85 86 |
# 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 junk data, to elicit an error message socket.syswrite("\0" * 64) # test if we've received any data socket.sysread(1) end end return true rescue Timeout::Error return nil rescue SocketError, SystemCallError return false end end |
- (nil) udp_recv(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... }
Creates a new UDPServer listening on a given host and port, accepts only one message from a client.
433 434 435 436 437 438 439 |
# File 'lib/ronin/network/udp/udp.rb', line 433 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 |
- (true) udp_send(data, host, port, local_host = nil, local_port = nil)
Connects to a specified host and port, sends the given data and then closes the connection.
243 244 245 246 247 248 249 |
# File 'lib/ronin/network/udp/udp.rb', line 243 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 |
- (UDPServer) udp_server(port = nil, host = nil) {|server| ... }
Creates a new UDPServer listening on a given host and port.
307 308 309 310 311 312 313 314 315 316 |
# File 'lib/ronin/network/udp/udp.rb', line 307 def udp_server(port=nil,host=nil) port = port.to_i host = (host || '0.0.0.0').to_s server = UDPSocket.new server.bind(host,port) yield server if block_given? return server end |
- (nil) udp_server_loop(port = nil, host = nil) {|server, (client_host, client_port), mesg| ... }
Creates a new UDPServer listening on a given host and port, accepting messages from clients in a loop.
386 387 388 389 390 391 392 393 394 |
# File 'lib/ronin/network/udp/udp.rb', line 386 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 |
- (nil) udp_server_session(port = nil, host = nil) {|server| ... }
Creates a new temporary UDPServer listening on a given host and port.
343 344 345 346 347 |
# File 'lib/ronin/network/udp/udp.rb', line 343 def udp_server_session(port=nil,host=nil,&block) server = udp_server(port,host,&block) server.close() return nil end |
- (nil) udp_session(host, port, local_host = nil, local_port = nil) {|socket| ... }
Creates a new temporary UDPSocket object, connected to the given host and port.
204 205 206 207 208 209 210 |
# File 'lib/ronin/network/udp/udp.rb', line 204 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 |