Method: Rex::Socket.source_address
- Defined in:
- lib/rex/socket.rb
.source_address(dest = '8.8.8.8', comm = ::Rex::Socket::Comm::Local) ⇒ Object
This method does NOT send any traffic to the destination, instead, it uses a “bound” UDP socket to determine what source address we would use to communicate with the specified destination. The destination defaults to Google’s DNS server to make the standard behavior determine which IP we would use to communicate with the internet.
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/rex/socket.rb', line 588 def self.source_address(dest='8.8.8.8', comm = ::Rex::Socket::Comm::Local) begin s = self.create_udp( 'PeerHost' => dest, 'PeerPort' => 31337, 'Comm' => comm ) r = s.getsockname[1] s.close # Trim off the trailing interface ID for link-local IPv6 return r.split('%').first rescue ::Exception return '127.0.0.1' end end |