guess_os 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/guess_os/host.rb +4 -0
- data/lib/guess_os/type/windows.rb +67 -11
- data/lib/guess_os/type.rb +6 -15
- data/lib/guess_os/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be86469e07373cbb16f984b73bb740c26b014c352bcb8a3112cd90cc4aa3418
|
4
|
+
data.tar.gz: a7a7760ab74ffc209f7f3e852e5674a13108de1ebaf250408ee8397d9fed9123
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 214db1350922347cfff01b453669258e67ea2b33ad92558c3eb7f6421ae92751c22c5308ea85c7a822b7a65270d0f3e3a33b5a1b2af5c30c0608eea7425165a4
|
7
|
+
data.tar.gz: dc4c9df949498c7246201d69b549f59de51680918f828bac1fae95cbdfbabba9e869f32ba4a3ba293b297879c225dd5cd6dc2592c20b16812212cd496f48b6b7
|
data/lib/guess_os/host.rb
CHANGED
@@ -1,26 +1,82 @@
|
|
1
1
|
class Windows
|
2
2
|
def self.guess(host)
|
3
3
|
conn = GuessOS::Conn.new(host)
|
4
|
-
|
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
|
-
|
41
|
+
command = "ver"
|
42
|
+
conn.exec(command)
|
8
43
|
|
9
44
|
identified = conn.ok && conn.last_output.include?("Windows")
|
10
|
-
return GuessOS::OS.
|
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
|
-
|
57
|
+
GuessOS::OS.unkown
|
18
58
|
end
|
19
|
-
|
59
|
+
end
|
20
60
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
data/lib/guess_os/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2023-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|