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 44
55require 'rest-client'
66require 'socket'
7+ require 'os'
78
89def network_info
910 # Grabs public WAN address.
@@ -23,29 +24,43 @@ def network_info
2324 exit ( 1 )
2425 end
2526
26- # Greps scutil for DNS server.
27+ # Greps either scutil or resolv.conf for DNS server.
2728 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
2937 rescue
3038 puts "Can't find DNS"
3139 exit ( 1 )
3240 end
3341
34- # Greps netstat for router address.
42+ # Greps netstat or ip route for router address.
3543 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
3752 rescue
3853 puts "Can't find Router"
3954 exit ( 1 )
4055 end
4156
4257 puts
43- puts "======================"
58+ puts "======================= "
4459 puts "| WAN: #{ response } "
4560 puts "| LAN(s): #{ lans . join ( ', ' ) } "
4661 puts "| ROUTER: #{ router } "
4762 puts "| DNS: #{ dns } "
48- puts "======================"
63+ puts "======================= "
4964 puts
5065end
5166
You can’t perform that action at this time.
0 commit comments