guess_os 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89004a256626a3a6a8275aa5caf484caf1463a1c3c1bdb1c32f64f52fdabdd4a
4
- data.tar.gz: d2c9becce5271e407a582079de1b00d9da5a93fc8c6d7bd6292f989c918e511c
3
+ metadata.gz: 0be86469e07373cbb16f984b73bb740c26b014c352bcb8a3112cd90cc4aa3418
4
+ data.tar.gz: a7a7760ab74ffc209f7f3e852e5674a13108de1ebaf250408ee8397d9fed9123
5
5
  SHA512:
6
- metadata.gz: 0e5322b66cc4582261c064d9f3c2a1e1b0fbc4b91da37dc64274526df7f283ab7f15634021eb1aba49533127788d55efa8645723a0ca45c8025f0c3666854e52
7
- data.tar.gz: 12cae8e6292a805ec368e0ccda51284d35072693166ba0da65088c9156f42925ec4f3050b1d68426a2bc31a7df767a5ed125ad7b2774ee37be4f7cefde0ab6fa
6
+ metadata.gz: 214db1350922347cfff01b453669258e67ea2b33ad92558c3eb7f6421ae92751c22c5308ea85c7a822b7a65270d0f3e3a33b5a1b2af5c30c0608eea7425165a4
7
+ data.tar.gz: dc4c9df949498c7246201d69b549f59de51680918f828bac1fae95cbdfbabba9e869f32ba4a3ba293b297879c225dd5cd6dc2592c20b16812212cd496f48b6b7
data/lib/guess_os/host.rb CHANGED
@@ -22,5 +22,9 @@ module GuessOS
22
22
  def remote?
23
23
  !local?
24
24
  end
25
+
26
+ def self.unkown
27
+ GuessOS::OS.new(:unkown, :unkown, "Unkown")
28
+ end
25
29
  end
26
30
  end
@@ -1,26 +1,82 @@
1
1
  class Windows
2
2
  def self.guess(host)
3
3
  conn = GuessOS::Conn.new(host)
4
- command = "ver"
4
+
5
+ os = try_with_regedit(conn)
6
+ return os unless os.type == :unkown
7
+
8
+ os = try_with_ver(conn)
9
+ return os unless os.type == :unkown
10
+
11
+ os = try_with_folder(conn)
12
+ return os unless os.type == :unkown
13
+ end
14
+
15
+ def self.try_with_regedit(conn)
16
+ command = 'run "reg query \"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\" /t REG_SZ'
5
17
  conn.exec(command)
18
+
19
+ identified = conn.ok && conn.last_output.include?("Windows")
20
+ return GuessOS::OS.unkown unless identified
21
+
22
+ output = conn.last_output
23
+ begin
24
+ lines = output.split("\n")
25
+ filter = lines.filter { _1.include? "ProductName" }
26
+ filter[0].gsub!("ProductName", "")
27
+ filter[0].gsub!("REG_SZ", "")
28
+
29
+ desc = filter[0].strip
30
+ items = desc.split
31
+ name = "#{items[0]} #{items[1]}"
32
+
33
+ GuessOS::OS.new(:windows, name, desc)
34
+ rescue
35
+ GuessOS::OS.unkown
36
+ end
37
+ end
38
+
39
+ def self.try_with_ver(conn)
6
40
  # ver => Microsoft Windows [Version 10.0.20348.469]
7
- # command = 'echo %windir%' => Windows
41
+ command = "ver"
42
+ conn.exec(command)
8
43
 
9
44
  identified = conn.ok && conn.last_output.include?("Windows")
10
- return GuessOS::OS.new(:unkown, :unkown, conn.status) unless identified
45
+ return GuessOS::OS.unkown unless identified
11
46
 
12
47
  output = conn.last_output
13
48
  begin
14
- output.tr!("\r", ".")
15
- output.tr!("\n", ".")
49
+ output.tr!("\r", "")
50
+ output.tr!("\n", "")
51
+ items = output.split
52
+ type = :windows
53
+ name = "windows #{items[3].split(".").first}"
54
+ desc = output
55
+ GuessOS::OS.new(type, name, desc)
16
56
  rescue
17
- # nothing
57
+ GuessOS::OS.unkown
18
58
  end
19
- items = output.split
59
+ end
20
60
 
21
- type = :windows
22
- name = "windows #{items[3].split(".").first}"
23
- desc = output
24
- GuessOS::OS.new(type, name, desc)
61
+ def self.try_with_folder(conn)
62
+ # command = 'echo %windir%' => Windows
63
+ command = "cd c:\windows"
64
+ conn.exec(command)
65
+
66
+ identified = conn.ok && conn.last_output.include?("Windows")
67
+ return GuessOS::OS.unkown unless identified
68
+
69
+ output = conn.last_output
70
+ begin
71
+ lines = output.split("\n")
72
+ filter = lines.filter { _1.include? "Volume" }
73
+ items = filter[0].split
74
+ type = :windows
75
+ name = items[-2, 2].join(" ").to_s
76
+ desc = filter[0]
77
+ GuessOS::OS.new(type, name, desc)
78
+ rescue
79
+ GuessOS::OS.unkown
80
+ end
25
81
  end
26
82
  end
data/lib/guess_os/type.rb CHANGED
@@ -2,22 +2,13 @@ require_relative "type/all"
2
2
 
3
3
  module GuessOS
4
4
  class Type
5
- def self.guess(host)
6
- os = Windows.guess(host)
7
- return os unless os.type == :unkown
8
-
9
- os = GNULinux.guess(host)
10
- return os unless os.type == :unkown
11
-
12
- os = MacOS.guess(host)
13
- return os unless os.type == :unkown
14
-
15
- os = Cygwin.guess(host)
16
- return os unless os.type == :unkown
17
-
18
- os = Minix.guess(host)
19
- return os unless os.type == :unkown
5
+ TYPES = [Windows, GNULinux, MacOS, Cygwin, Minix]
20
6
 
7
+ def self.guess(host)
8
+ TYPES.each do |klass|
9
+ os = klass.send :guess, host
10
+ return os unless os.type == :unkown
11
+ end
21
12
  os
22
13
  end
23
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GuessOS
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.12"
5
5
  NAME = "guess_os"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guess_os
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-17 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh