Class: ItTools::VpnTools

Inherits:
Object
  • Object
show all
Defined in:
lib/it_tools/it_tools.rb

Instance Method Summary collapse

Instance Method Details

#is_port_open?(ip, port) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/it_tools/it_tools.rb', line 7

def is_port_open?(ip, port)
  begin
    Timeout::timeout(1) do
      begin
        s = TCPSocket.new(ip, port)
        s.close
        return true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
        return false
      end
    end
  rescue Timeout::Error
  end
  return false
end

#login_to_urlObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/it_tools/it_tools.rb', line 31

def 
  desired_url = "https://secure-ausomxnga.crmondemand.com/"
  port = 443
  username = '[email protected]'
  password = 'Veronica8Li'
  puts "[URL]: " + desired_url
  puts "[PORT]: #{port}"
  puts "[USERNAME]: " + username

  # Failed: Oracle Access Manager Version: 11.1.1.5.0


  (desired_url, port, username, password)
end

#login_to_url2(url, port, username, password, limit = 10) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/it_tools/it_tools.rb', line 46

def (url, port, username, password, limit = 10)
  # You should choose a better exception.
  raise ArgumentError, 'too many HTTP redirects' if limit == 0

  uri = URI(url)

  req = Net::HTTP::Get.new(uri.request_uri)
  req.basic_auth username, password

  res = Net::HTTP.start(uri.host, port, :use_ssl => uri.scheme == 'https') {|http|
    http.request(req)
  }

  case res
  when Net::HTTPSuccess then
    puts "Successfully logged in." # res.body
  when Net::HTTPRedirection then
    location = res['location']
    warn "redirected to #{location}"
    (location, port, username, password, limit - 1)
  else
    response.value
  end
end

#on_vpnObject



23
24
25
26
27
28
29
# File 'lib/it_tools/it_tools.rb', line 23

def on_vpn
  if is_port_open?("spicevan.com", 22)
    return FALSE
  else
    return TRUE
  end
end