Sha256: 15d92343e0ce85693c71e715af9ba96ce6e77f11a0f18c702fe9d27795606dc5

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

# encoding: ascii-8bit

# Copyright 2022 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved

require 'socket'
require 'resolv'

# OpenC3 specific additions to the Ruby Socket class
class Socket
  # @return [String] The IP address of the current machine
  def self.get_own_ip_address
    Resolv.getaddress Socket.gethostname
  end

  # @param ip_address [String] IP address in the form xxx.xxx.xxx.xxx
  # @return [String] The hostname of the given IP address or 'UNKNOWN' if the
  #   lookup fails
  def self.lookup_hostname_from_ip(ip_address)
    return Resolv.getname(ip_address)
  rescue
    return 'UNKNOWN'
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openc3-5.0.11 lib/openc3/core_ext/socket.rb
openc3-5.0.10 lib/openc3/core_ext/socket.rb
openc3-5.0.9 lib/openc3/core_ext/socket.rb
openc3-5.0.8 lib/openc3/core_ext/socket.rb
openc3-5.0.7 lib/openc3/core_ext/socket.rb
openc3-5.0.6 lib/openc3/core_ext/socket.rb