File: network_connection.rb

package info (click to toggle)
ruby-webmock 3.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,172 kB
  • sloc: ruby: 12,829; makefile: 6
file content (19 lines) | stat: -rw-r--r-- 321 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'timeout'
require 'socket'

module NetworkConnection
  def self.connect_to(host, port, timeout=10)
    Timeout.timeout(timeout) do
      TCPSocket.new(host, port)
    end
  end

  def self.is_network_available?
    begin
      self.connect_to("8.8.8.8", 53, 5)
      true
    rescue
      false
    end
  end
end