This repository was archived by the owner on Aug 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change 4
4
5
5
require 'rest-client'
6
6
require 'socket'
7
+ require 'os'
7
8
8
9
def network_info
9
10
# Grabs public WAN address.
@@ -23,29 +24,43 @@ def network_info
23
24
exit ( 1 )
24
25
end
25
26
26
- # Greps scutil for DNS server.
27
+ # Greps either scutil or resolv.conf for DNS server.
27
28
begin
28
- dns = %x[scutil --dns | grep nameserver | head -1 | awk '{print$3}']
29
+ if OS . linux?
30
+ dns = %x[cat /etc/resolv.conf | grep nameserver | head -1 | awk '{print$2}']
31
+ elsif OS . mac?
32
+ dns = %x[scutil --dns | grep nameserver | head -1 | awk '{print$3}']
33
+ else
34
+ puts "OS not supported!"
35
+ exit ( 1 )
36
+ end
29
37
rescue
30
38
puts "Can't find DNS"
31
39
exit ( 1 )
32
40
end
33
41
34
- # Greps netstat for router address.
42
+ # Greps netstat or ip route for router address.
35
43
begin
36
- router = %x[netstat -rn | grep default | head -1 | awk '{print$2}']
44
+ if OS . linux?
45
+ router = %x[ip route | grep default | head -1 | awk '{print$3}']
46
+ elsif OS . mac?
47
+ router = %x[netstat -rn | grep default | head -1 | awk '{print$2}']
48
+ else
49
+ puts "OS not supported!"
50
+ exit ( 1 )
51
+ end
37
52
rescue
38
53
puts "Can't find Router"
39
54
exit ( 1 )
40
55
end
41
56
42
57
puts
43
- puts "======================"
58
+ puts "======================= "
44
59
puts "| WAN: #{ response } "
45
60
puts "| LAN(s): #{ lans . join ( ', ' ) } "
46
61
puts "| ROUTER: #{ router } "
47
62
puts "| DNS: #{ dns } "
48
- puts "======================"
63
+ puts "======================= "
49
64
puts
50
65
end
51
66
You can’t perform that action at this time.
0 commit comments