jake-scripts 1.9.2 → 2.0.0
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/README.md +1 -1
- data/exe/currency +4 -3
- data/exe/movie +6 -7
- data/exe/stock +52 -52
- data/exe/weather +64 -57
- data/jake-scripts.gemspec +2 -2
- data/lib/jake/scripts/version.rb +1 -1
- metadata +5 -15
- data/exe/decrypt +0 -18
- data/exe/encrypt +0 -18
- data/exe/ip-geo +0 -116
- data/exe/ip-list +0 -67
- data/exe/ip-location +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ea0a6772ce2fe56dd66e9c7f0ae4882eff24680
|
4
|
+
data.tar.gz: d29417796bf90f034b1a0ee6102f83d50eda22be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7f110312fc6efafc414f0b60187b05613ca1b0ca32c9e50f215a7fc4b3bfbd3692df3659be68326f384a95da6ae9c1455df97217aa5fe0e945601191ef41ab
|
7
|
+
data.tar.gz: 2ee209169307a2ec8eda247eea4a534b960980649e84c937379efee68844fb521e6f5a87f38e2474626c87ea66e6f13ce76cb046ab7da94255f39defdf9b3589
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Jake::Scripts
|
2
|
-
|
2
|
+
#
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jake/scripts`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
5
|
TODO: Delete this and the text above, and describe your gem
|
data/exe/currency
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
# Uses Ruby Money for accuracy
|
5
5
|
# Uses Fixer.io for exchange data
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'uri'
|
8
|
+
require 'net/http'
|
8
9
|
require 'json'
|
9
10
|
require 'money'
|
10
11
|
require 'monetize'
|
@@ -22,8 +23,8 @@ def conversion
|
|
22
23
|
|
23
24
|
# Fetches API info
|
24
25
|
begin
|
25
|
-
|
26
|
-
response =
|
26
|
+
uri = URI("http://api.fixer.io/latest?base=#{base_currency}&symbols=#{convert_to}")
|
27
|
+
response = Net::HTTP.get(uri)
|
27
28
|
parsed = JSON.parse(response)
|
28
29
|
convert_factor = (parsed['rates'][convert_to])
|
29
30
|
rescue
|
data/exe/movie
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# CLI app that searched movies and returns info
|
3
3
|
|
4
|
-
require 'rest-client'
|
5
4
|
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http'
|
6
7
|
|
7
|
-
# Word wrapping
|
8
|
+
# Word wrapping for consise output
|
8
9
|
def wrap(s, width = 78)
|
9
10
|
s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n| ")
|
10
11
|
end
|
@@ -13,17 +14,15 @@ def movie
|
|
13
14
|
# This is a live API key, don't absue it
|
14
15
|
api_key = ENV['OMDBAPI_API_KEY'] || '946f500a'
|
15
16
|
|
16
|
-
|
17
|
-
print 'Movie => '
|
18
|
-
movie_name = gets.chomp
|
17
|
+
movie_name = ARGV
|
19
18
|
|
20
19
|
# Program escape statements
|
21
20
|
if movie_name == 'quit' || movie_name == 'exit'
|
22
21
|
puts
|
23
22
|
exit(1)
|
24
23
|
else
|
25
|
-
|
26
|
-
response =
|
24
|
+
uri = URI("http://www.omdbapi.com/?t=#{movie_name}&apikey=#{api_key}")
|
25
|
+
response = Net::HTTP.get(uri)
|
27
26
|
info = JSON.parse(response)
|
28
27
|
end
|
29
28
|
|
data/exe/stock
CHANGED
@@ -1,67 +1,67 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# CLI app that searches stock info by symbol.
|
3
3
|
|
4
|
-
require 'rest-client'
|
5
4
|
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http'
|
7
|
+
require 'colorize'
|
6
8
|
|
7
9
|
def stock_search
|
8
|
-
puts
|
9
|
-
print 'Stock => '
|
10
|
-
symbol = gets.chomp
|
11
10
|
|
12
|
-
|
13
|
-
exit(1)
|
14
|
-
else
|
15
|
-
begin
|
16
|
-
# Takes user input and generates ticker symbol.
|
17
|
-
url = "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=#{symbol}®ion=1&lang=en%22"
|
18
|
-
response = RestClient.get(url)
|
19
|
-
parsed = JSON.parse(response)
|
20
|
-
parsed_symbol = parsed['ResultSet']['Result'][0]['symbol']
|
21
|
-
rescue
|
22
|
-
puts
|
23
|
-
puts 'Invalid Search'
|
24
|
-
puts
|
25
|
-
exit(1)
|
26
|
-
end
|
11
|
+
symbol = ARGV.join(" ")
|
27
12
|
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
# Takes user input and generates ticker symbol.
|
14
|
+
begin
|
15
|
+
uri = URI("http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=#{symbol}&lang=en%22")
|
16
|
+
response = Net::HTTP.get(uri)
|
31
17
|
parsed = JSON.parse(response)
|
18
|
+
parsed_symbol = parsed['ResultSet']['Result'][0]['symbol'].split(".")[0]
|
19
|
+
rescue
|
20
|
+
puts "Stock not found"
|
21
|
+
exit(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Use ticker symbol to fetch quote data
|
25
|
+
uri = URI("https://api.iextrading.com/1.0/stock/#{parsed_symbol}/quote")
|
26
|
+
response = Net::HTTP.get(uri)
|
27
|
+
if response == "Unknown symbol"
|
28
|
+
puts "Stock not found"
|
29
|
+
exit(1)
|
30
|
+
end
|
31
|
+
quote = JSON.parse(response)
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
33
|
+
# Shorten exchange string
|
34
|
+
case quote['primaryExchange']
|
35
|
+
when "Nasdaq Global Select"
|
36
|
+
exchange = "NASDAQ"
|
37
|
+
when "New York Stock Exchange"
|
38
|
+
exchange = "NYSE"
|
39
|
+
end
|
40
|
+
|
41
|
+
puts
|
42
|
+
puts "=========================="
|
43
|
+
puts "Symbol: #{quote['symbol']}"
|
44
|
+
puts "Price: $#{quote['latestPrice']}"
|
45
|
+
|
46
|
+
# Color output for price change
|
47
|
+
if quote['change'].positive?
|
48
|
+
puts "Chg: " + "+#{quote['change']}".green
|
49
|
+
else
|
50
|
+
puts "Chg: " + "#{quote['change']}".red
|
51
|
+
end
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
puts "| Open: $#{parsed_open}"
|
56
|
-
puts "| High: $#{parsed_high}"
|
57
|
-
puts "| Price Chg: $#{parsed_price_chg}"
|
58
|
-
puts "| Price Chg % : #{parsed_price_pct}"
|
59
|
-
puts "| Volume: #{parsed_volume}"
|
60
|
-
puts "| Echange: #{parsed_exchange}"
|
61
|
-
puts '======================'
|
62
|
-
puts
|
63
|
-
end
|
53
|
+
# Color output for percent price change
|
54
|
+
if quote['changePercent'].positive?
|
55
|
+
puts "Chg %: " + "+#{quote['changePercent']}%".green
|
56
|
+
else
|
57
|
+
puts "Chg %: " + "#{quote['changePercent']}%".red
|
64
58
|
end
|
59
|
+
|
60
|
+
puts "PE Ratio: #{quote['peRatio']}"
|
61
|
+
puts "Mkt Cap: $#{quote['marketCap']}"
|
62
|
+
puts "Exchange: #{exchange}"
|
63
|
+
puts "=========================="
|
64
|
+
puts
|
65
65
|
end
|
66
66
|
|
67
67
|
stock_search
|
data/exe/weather
CHANGED
@@ -1,72 +1,79 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# CLI app that brings in current location weather.
|
3
3
|
|
4
|
-
require 'rest-client'
|
5
4
|
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http'
|
6
7
|
|
7
|
-
def
|
8
|
-
# This key is functional, please don't abuse it
|
8
|
+
def weather
|
9
9
|
api_key = ENV['APIXU_API_KEY'] || "6510b92495fd472ca30155709172803&q"
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
ip = get_ip
|
12
|
+
city = ARGV[0] || ip["city"]
|
13
|
+
state = ARGV[1] || ip["region"]
|
14
|
+
country = ip["countryCode"]
|
15
|
+
|
16
|
+
weather = get_weather(api_key, city, state)
|
17
|
+
|
18
|
+
if country == "US"
|
19
|
+
us_printer(weather)
|
20
|
+
else
|
21
|
+
intl_printer(weather)
|
20
22
|
end
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
def get_ip
|
26
|
+
uri = URI("http://ip-api.com/json")
|
27
|
+
response = Net::HTTP.get(uri)
|
28
|
+
JSON.parse(response)
|
29
|
+
end
|
26
30
|
|
27
|
-
|
31
|
+
def get_weather(api_key, city, state)
|
32
|
+
uri = URI("https://api.apixu.com/v1/current.json?key=#{api_key}=#{city}+#{state}")
|
33
|
+
response = Net::HTTP.get(uri)
|
34
|
+
JSON.parse(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def us_printer(parsed)
|
38
|
+
# Printer for US users
|
39
|
+
location_name = parsed["location"]["name"]
|
40
|
+
temp = parsed["current"]["temp_f"]
|
41
|
+
wind_speed = parsed["current"]["wind_mph"]
|
42
|
+
humidity = parsed["current"]["humidity"]
|
43
|
+
feels_like = parsed["current"]["feelslike_f"]
|
44
|
+
visibility = parsed["current"]["vis_miles"]
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
46
|
+
puts
|
47
|
+
puts "======================"
|
48
|
+
puts "City: #{location_name}"
|
49
|
+
puts "Temp: #{temp}°F"
|
50
|
+
puts "Feels Like: #{feels_like}°F"
|
51
|
+
puts "Humidity: #{humidity}%"
|
52
|
+
puts "Wind Speed: #{wind_speed} mph"
|
53
|
+
puts "Visibility: #{visibility} mi"
|
54
|
+
puts "======================"
|
55
|
+
puts
|
56
|
+
end
|
37
57
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
puts "| Visibility: #{visibility} mi"
|
47
|
-
puts "======================"
|
48
|
-
puts
|
49
|
-
else
|
50
|
-
# Assigning values to variables
|
51
|
-
location_name = parsed["location"]["name"]
|
52
|
-
temp = parsed["current"]["temp_c"]
|
53
|
-
wind_speed = parsed["current"]["wind_kph"]
|
54
|
-
humidity = parsed["current"]["humidity"]
|
55
|
-
feels_like = parsed["current"]["feelslike_c"]
|
56
|
-
visibility = parsed["current"]["vis_km"]
|
58
|
+
def intl_printer(parsed)
|
59
|
+
# Printer for metric users
|
60
|
+
location_name = parsed["location"]["name"]
|
61
|
+
temp = parsed["current"]["temp_c"]
|
62
|
+
wind_speed = parsed["current"]["wind_kph"]
|
63
|
+
humidity = parsed["current"]["humidity"]
|
64
|
+
feels_like = parsed["current"]["feelslike_c"]
|
65
|
+
visibility = parsed["current"]["vis_km"]
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
puts
|
69
|
-
end
|
67
|
+
puts
|
68
|
+
puts "======================"
|
69
|
+
puts "City: #{location_name}"
|
70
|
+
puts "Temp: #{temp}°C"
|
71
|
+
puts "Feels Like: #{feels_like}°C"
|
72
|
+
puts "Humidity: #{humidity}%"
|
73
|
+
puts "Wind Speed: #{wind_speed} kph"
|
74
|
+
puts "Visibility: #{visibility} km"
|
75
|
+
puts "======================"
|
76
|
+
puts
|
70
77
|
end
|
71
78
|
|
72
|
-
|
79
|
+
weather
|
data/jake-scripts.gemspec
CHANGED
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.15"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
-
spec.add_development_dependency "
|
25
|
+
spec.add_development_dependency "colorize"
|
26
26
|
spec.add_development_dependency "money", "~> 6.9.0"
|
27
27
|
spec.add_development_dependency "monetize", "~> 1.7.0"
|
28
28
|
|
29
|
-
spec.add_runtime_dependency "
|
29
|
+
spec.add_runtime_dependency "colorize"
|
30
30
|
spec.add_runtime_dependency "money", "~> 6.9.0"
|
31
31
|
spec.add_runtime_dependency "monetize", "~> 1.7.0"
|
32
32
|
spec.add_runtime_dependency "os"
|
data/lib/jake/scripts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jake-scripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: colorize
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.7.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: colorize
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -183,11 +183,6 @@ email:
|
|
183
183
|
- jakewmeyer@gmail.com
|
184
184
|
executables:
|
185
185
|
- currency
|
186
|
-
- decrypt
|
187
|
-
- encrypt
|
188
|
-
- ip-geo
|
189
|
-
- ip-list
|
190
|
-
- ip-location
|
191
186
|
- movie
|
192
187
|
- stock
|
193
188
|
- weather
|
@@ -203,11 +198,6 @@ files:
|
|
203
198
|
- bin/console
|
204
199
|
- bin/setup
|
205
200
|
- exe/currency
|
206
|
-
- exe/decrypt
|
207
|
-
- exe/encrypt
|
208
|
-
- exe/ip-geo
|
209
|
-
- exe/ip-list
|
210
|
-
- exe/ip-location
|
211
201
|
- exe/movie
|
212
202
|
- exe/stock
|
213
203
|
- exe/weather
|
@@ -233,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
223
|
version: '0'
|
234
224
|
requirements: []
|
235
225
|
rubyforge_project:
|
236
|
-
rubygems_version: 2.
|
226
|
+
rubygems_version: 2.5.2
|
237
227
|
signing_key:
|
238
228
|
specification_version: 4
|
239
229
|
summary: Gem containing my scripts, tools, and utilities
|
data/exe/decrypt
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Decrypts files easily using
|
4
|
-
# openssl commands. Essentially
|
5
|
-
# an easy wrapper for openssl
|
6
|
-
|
7
|
-
# Ex. $ decrypt encrypted.txt names.txt
|
8
|
-
|
9
|
-
def decrypt
|
10
|
-
input_file = ARGV[0]
|
11
|
-
output_file = ARGV[1]
|
12
|
-
unless system("openssl enc -aes-256-cbc -d -a -in #{input_file} -out #{output_file}")
|
13
|
-
puts "Files not found!"
|
14
|
-
end
|
15
|
-
puts 'Sucessfully decrypted'
|
16
|
-
end
|
17
|
-
|
18
|
-
decrypt
|
data/exe/encrypt
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Encrypts files easily using
|
4
|
-
# openssl commands. Essentially
|
5
|
-
# an easy wrapper for openssl
|
6
|
-
|
7
|
-
# Ex. $ encrypt names.txt encrypted.txt
|
8
|
-
|
9
|
-
def encrypt
|
10
|
-
input_file = ARGV[0]
|
11
|
-
output_file = ARGV[1]
|
12
|
-
unless system("openssl enc -aes-256-cbc -salt -a -in #{input_file} -out #{output_file}")
|
13
|
-
puts "Files not found!"
|
14
|
-
end
|
15
|
-
puts "Sucessfully encrypted"
|
16
|
-
end
|
17
|
-
|
18
|
-
encrypt
|
data/exe/ip-geo
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#CLI program to find IP geolocation
|
3
|
-
|
4
|
-
require 'rest-client'
|
5
|
-
require 'json'
|
6
|
-
require 'optparse'
|
7
|
-
|
8
|
-
|
9
|
-
options = {}
|
10
|
-
OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage: example.rb [options]"
|
12
|
-
|
13
|
-
opts.on("-m", "--machine VARIABLE", "Machine Readable") do |v|
|
14
|
-
options[:var] = v
|
15
|
-
end
|
16
|
-
end.parse!
|
17
|
-
|
18
|
-
# Ex. ip
|
19
|
-
opt = options[:var]
|
20
|
-
|
21
|
-
# Ex. 8.8.8.8
|
22
|
-
*arg = ARGV
|
23
|
-
|
24
|
-
if opt == nil && arg == nil
|
25
|
-
puts
|
26
|
-
print 'IP => '
|
27
|
-
ip = gets.chomp
|
28
|
-
|
29
|
-
url = "http://ip-api.com/json/#{ip}"
|
30
|
-
response = RestClient.get(url)
|
31
|
-
info = JSON.parse(response)
|
32
|
-
|
33
|
-
if info['status'] == 'fail'
|
34
|
-
puts 'No IP found'
|
35
|
-
else
|
36
|
-
puts
|
37
|
-
puts '============================='
|
38
|
-
puts "| IP: #{info['query']}"
|
39
|
-
puts "| City: #{info['city']}"
|
40
|
-
puts "| Region: #{info['region']}"
|
41
|
-
puts "| Country: #{info['country']}"
|
42
|
-
puts "| ZIP: #{info['zip']}"
|
43
|
-
puts "| ISP: #{info['isp']}"
|
44
|
-
puts '============================='
|
45
|
-
puts
|
46
|
-
end
|
47
|
-
elsif opt == nil && arg != nil
|
48
|
-
url = "http://ip-api.com/json/#{arg.join}"
|
49
|
-
response = RestClient.get(url)
|
50
|
-
info = JSON.parse(response)
|
51
|
-
|
52
|
-
if info['status'] == 'fail'
|
53
|
-
puts 'No IP found'
|
54
|
-
else
|
55
|
-
puts
|
56
|
-
puts '============================='
|
57
|
-
puts "| IP: #{info['query']}"
|
58
|
-
puts "| City: #{info['city']}"
|
59
|
-
puts "| Region: #{info['region']}"
|
60
|
-
puts "| Country: #{info['country']}"
|
61
|
-
puts "| ZIP: #{info['zip']}"
|
62
|
-
puts "| ISP: #{info['isp']}"
|
63
|
-
puts '============================='
|
64
|
-
puts
|
65
|
-
end
|
66
|
-
elsif opt != nil && arg != nil
|
67
|
-
url = "http://ip-api.com/json/#{arg.join}"
|
68
|
-
response = RestClient.get(url)
|
69
|
-
info = JSON.parse(response)
|
70
|
-
|
71
|
-
if info['status'] == 'fail'
|
72
|
-
puts 'No IP info'
|
73
|
-
else
|
74
|
-
if opt == 'ip'
|
75
|
-
puts info['query']
|
76
|
-
elsif opt == 'city'
|
77
|
-
puts info['city']
|
78
|
-
elsif opt == 'region'
|
79
|
-
puts info['region']
|
80
|
-
elsif opt == 'country'
|
81
|
-
puts info['country']
|
82
|
-
elsif opt == 'zip'
|
83
|
-
puts info['zip']
|
84
|
-
elsif opt == 'isp'
|
85
|
-
puts info['isp']
|
86
|
-
else
|
87
|
-
puts 'Bad input'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
elsif opt != nil && arg == nil
|
91
|
-
url = "http://ip-api.com/json/#{arg.join}"
|
92
|
-
response = RestClient.get(url)
|
93
|
-
info = JSON.parse(response)
|
94
|
-
|
95
|
-
if info['status'] == 'fail'
|
96
|
-
puts 'No IP info'
|
97
|
-
else
|
98
|
-
if opt == 'ip'
|
99
|
-
puts info['query']
|
100
|
-
elsif opt == 'city'
|
101
|
-
puts info['city']
|
102
|
-
elsif opt == 'region'
|
103
|
-
puts info['region']
|
104
|
-
elsif opt == 'country'
|
105
|
-
puts info['country']
|
106
|
-
elsif opt == 'zip'
|
107
|
-
puts info['zip']
|
108
|
-
elsif opt == 'isp'
|
109
|
-
puts info['isp']
|
110
|
-
else
|
111
|
-
puts 'Bad input'
|
112
|
-
end
|
113
|
-
end
|
114
|
-
else
|
115
|
-
puts 'Bad input'
|
116
|
-
end
|
data/exe/ip-list
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Gets WAN IP, Lan IP, Router IP, and DNS Server.
|
3
|
-
# Compiles to a nice list.
|
4
|
-
|
5
|
-
require 'rest-client'
|
6
|
-
require 'socket'
|
7
|
-
require 'os'
|
8
|
-
|
9
|
-
def network_info
|
10
|
-
# Grabs public WAN address.
|
11
|
-
begin
|
12
|
-
url = "https://api.ipify.org"
|
13
|
-
response = RestClient.get(url)
|
14
|
-
rescue
|
15
|
-
puts "Can't find WAN"
|
16
|
-
exit(1)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Grabs assigned IP and formats it.
|
20
|
-
begin
|
21
|
-
lans = Socket.ip_address_list.select{|intf| intf.ipv4_private?}.map { |intf| intf.ip_address }
|
22
|
-
rescue
|
23
|
-
puts "Cant find LAN"
|
24
|
-
exit(1)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Greps either scutil or resolv.conf for DNS server.
|
28
|
-
begin
|
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
|
37
|
-
rescue
|
38
|
-
puts "Can't find DNS"
|
39
|
-
exit(1)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Greps netstat or ip route for router address.
|
43
|
-
begin
|
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
|
52
|
-
rescue
|
53
|
-
puts "Can't find Router"
|
54
|
-
exit(1)
|
55
|
-
end
|
56
|
-
|
57
|
-
puts
|
58
|
-
puts "======================="
|
59
|
-
puts "| WAN: #{response}"
|
60
|
-
puts "| LAN(s): #{lans.join(', ')}"
|
61
|
-
puts "| ROUTER: #{router}"
|
62
|
-
puts "| DNS: #{dns}"
|
63
|
-
puts "======================="
|
64
|
-
puts
|
65
|
-
end
|
66
|
-
|
67
|
-
network_info
|
data/exe/ip-location
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Returns geolocation data for current IP
|
3
|
-
|
4
|
-
require 'rest-client'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
def ip_current_geo
|
8
|
-
begin
|
9
|
-
url = "http://ip-api.com/json"
|
10
|
-
response = RestClient.get(url)
|
11
|
-
info = JSON.parse(response)
|
12
|
-
rescue
|
13
|
-
puts
|
14
|
-
puts 'No IP found.'
|
15
|
-
puts
|
16
|
-
exit(1)
|
17
|
-
end
|
18
|
-
|
19
|
-
ip = info["query"]
|
20
|
-
city = info["city"]
|
21
|
-
region = info["region"]
|
22
|
-
country = info["country"]
|
23
|
-
isp = info["isp"]
|
24
|
-
zip = info['zip']
|
25
|
-
|
26
|
-
if city.nil?
|
27
|
-
puts
|
28
|
-
puts 'No IP found.'
|
29
|
-
puts
|
30
|
-
exit(1)
|
31
|
-
else
|
32
|
-
puts
|
33
|
-
puts '============================='
|
34
|
-
puts "| IP: #{ip}"
|
35
|
-
puts "| City: #{city}"
|
36
|
-
puts "| Region: #{region}"
|
37
|
-
puts "| Country: #{country}"
|
38
|
-
puts "| ZIP: #{zip}"
|
39
|
-
puts "| ISP: #{isp}"
|
40
|
-
puts '============================='
|
41
|
-
puts
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
ip_current_geo
|