module Arachni::Reactor::Connection::PeerInfo

@author Tasos “Zapotek” Laskos <tasos.laskos@gmail.com>

Public Instance Methods

peer_address() click to toggle source

@return [String]

Peer's IP address or socket path.
# File lib/arachni/reactor/connection/peer_info.rb, line 66
def peer_address
    peer_ip_address || peer_address_info[:path]
end
peer_address_info( resolve = false ) click to toggle source

@param [Bool] resolve

Resolve IP address to hostname.

@return [Hash]

Peer address information:

* IP socket:
    * Without `resolve`:

            {
                protocol:   'AF_INET',
                port:       10314,
                hostname:   '127.0.0.1',
                ip_address: '127.0.0.1'
            }

    * With `resolve`:

            {
                protocol:   'AF_INET',
                port:       10314,
                hostname:   'localhost',
                ip_address: '127.0.0.1'
            }

* UNIX-domain socket:

        {
            protocol: 'AF_UNIX',
            path:     '/tmp/my-socket'
        }
# File lib/arachni/reactor/connection/peer_info.rb, line 46
def peer_address_info( resolve = false )
    if Arachni::Reactor.supports_unix_sockets? && to_io.is_a?( UNIXSocket )
        {
            protocol: to_io.peeraddr.first,
            path:     to_io.path
        }
    else
        protocol, port, hostname, ip_address = to_io.peeraddr( resolve )

        {
            protocol:   protocol,
            port:       port,
            hostname:   hostname,
            ip_address: ip_address
        }
    end
end
peer_hostname() click to toggle source

@return [String]

Peer's hostname.
# File lib/arachni/reactor/connection/peer_info.rb, line 78
def peer_hostname
    peer_address_info(true)[:hostname]
end
peer_ip_address() click to toggle source

@return [String]

Peer's IP address.
# File lib/arachni/reactor/connection/peer_info.rb, line 72
def peer_ip_address
    peer_address_info[:ip_address]
end
peer_port() click to toggle source

@return [String]

Peer's port.
# File lib/arachni/reactor/connection/peer_info.rb, line 84
def peer_port
    peer_address_info[:port]
end