Ronin Network Examples
Examples of networking convenience methods provided by Ronin.
-
Test if a UDP port is open:
udp_open?('4.2.2.1',53) # => true
-
Test if a TCP port is open:
tcp_open?('example.com',80) # => true
-
Creating a UNIX Socket session, that will automatically be closed:
unix_session('/tmp/haproxy.stats.socket') do |socket| socket.puts("show stat") puts socket.readlines end
-
Connecting to a UNIX Socket:
unix_connect('/tmp/haproxy.stats.socket') # => #<UNIXSocket:...>
-
Opens a UNIX Socket and accepts one connection:
unix_accept('/tmp/race_condition.socket') do |socket| sockets.puts(buffer) end
-
Creating a UDP session which will be automatically closed:
udp_session('example.com',1212) do |socket| socket.write("PING") mesg, _ = socket.recv(1024) mesg.hexdump end
-
Listen on a port and receive UDP messages, infinitely:
udp_server_loop(1337) do |server,(host,port),mesg| print_info "#{host}:#{port}" mesg.hexdump end
-
Send data to a UDP Server:
udp_send(buffer,'example.com',1212)
-
Listen on a port, and receive only one UDP message:
udp_recv(1337) do |socket,(host,port),mesg| print_info "#{host}:#{port}" mesg.hexdump end
-
Listen on a TCP port and accept connections, infinitely:
tcp_server_loop(1337) do |client| client.write(buffer) end
-
Send data to a TCP Server:
tcp_send(buffer,'example.com',1212)
-
Listen on a port and accept the first TCP connection:
tcp_accept(1337) do |client| client.write(buffer) end
-
Creating a FTP session which will automatically be closed:
ftp_session('ftp.kernel.org') do |ftp| ftp.chdir('/pub') puts ftp.list end
-
Connecting to an FTP Server:
ftp_connect('www.example.com', :user => 'joe', :password => 'secret') # => #<Net::FTP:...>
-
Return the response Headers from a HTTP GET Request:
http_get_headers :url => 'http://example.com/'
-
Return the response body from a HTTP GET request:
http_get_body :url => 'http://example.com/'
-
Lookup an address of a Domain name:
dns_lookup 'example.com'
-
Lookup all addresses of a Domain name:
dns_lookup_all 'example.com'
-
Creating a SSL session which will be automatically closed:
ssl_session('github.com',443) do |socket| socket.write("GET /\r\n") puts socket.read end
-
Create a SSL Socket to a specified host and port:
socket = ssl_connect('github.com',443) # => #<OpenSSL::SSL::SSLSocket:0x00000002f60458>
-
Creating a TCP session which will be automatically closed:
tcp_session('www.example.com',1212) do |socket| socket.write("this is just a test\n") puts socket.readline end
-
Creating a TCP Socket to a specified host and port:
socket = tcp_connect('www.example.com',25) # => #<TCPSocket:0xb7bbde6c>
-
Grabbing the banner from a TCP service:
tcp_banner('www.example.com',22) # => "SSH-2.0-OpenSSH_4.3p2 Debian-8ubuntu1.4\n"