Skip to content

Instantly share code, notes, and snippets.

@shekkbuilder
Forked from picatz/basic_socket_usage.rb
Created April 26, 2017 06:23
Show Gist options
  • Select an option

  • Save shekkbuilder/0de8d381bc3e0188619d053d02d97e96 to your computer and use it in GitHub Desktop.

Select an option

Save shekkbuilder/0de8d381bc3e0188619d053d02d97e96 to your computer and use it in GitHub Desktop.
Violent Ruby: Banner Grabber - Basic Socket Usage
# coding: utf-8
# Basic socket usage to grab a banner.
# @author Kent 'picat' Gruber
require 'socket'
# Grab the banner of a given +ip+ address and +port+
# to attempt to connect to.
#
# @param ip [String] Target IP address.
# @param port [Integer] Target port.
#
# @return [String]
def grab_banner(ip, port)
TCPSocket.new(ip, port).recv(1024)
end
# Print the result of the method to STDOUT.
puts grab_banner('localhost', 2222)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment