whereisthis 1.2.0 → 1.3.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/lib/whereisthis.rb +37 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c82ef687409c12636a29e52813bafd64d0d02da8
|
4
|
+
data.tar.gz: 4cb44b41ad65db1f057e2451c104e6ce0ed053a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdb6617c56369e350613c11d5ab73b57a8b3258b0725c5a65503006021fe6ea602a492945e0ca435faea0cb1105bce7b8e1ea09572f597dad8692b8511a82454
|
7
|
+
data.tar.gz: b64303c8cb62f00a3131324ebea04bed9d07e024ae9219e52c9a66ed25f17e5ab5f731bc0e110e201235bc269d3694e32bc6cd71a23e6a0d010da65700decc75
|
data/lib/whereisthis.rb
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Whereisthis
|
4
|
+
#
|
5
|
+
# This is a simple command-line application to help determine
|
6
|
+
# the location information from a given ip address or url.
|
7
|
+
#
|
8
|
+
# Author:: Kent 'picat' Gruber
|
9
|
+
# Copyright:: Copyright (c) 2016 Kent Gruber
|
10
|
+
# License:: MIT
|
11
|
+
|
2
12
|
require 'socket'
|
3
13
|
require 'colorize'
|
4
14
|
require 'ipaddress'
|
@@ -6,12 +16,26 @@ require 'trollop'
|
|
6
16
|
require 'unirest'
|
7
17
|
|
8
18
|
module Whereisthis
|
9
|
-
|
19
|
+
|
20
|
+
# Specify version number.
|
21
|
+
VERSION = "1.3.0"
|
10
22
|
|
23
|
+
# .findout! is the main workhorse of this application. It starts
|
24
|
+
# the option parsing; and performs the main logic for basically
|
25
|
+
# everything.
|
26
|
+
#
|
27
|
+
# == Example
|
28
|
+
#
|
29
|
+
# # Typical use:
|
30
|
+
# require 'whereisthis'
|
31
|
+
# ARGV[0] = "8.8.8.8"
|
32
|
+
# Whereisthis.findout!
|
33
|
+
#
|
11
34
|
def self.findout!
|
12
|
-
# Default to a help menu
|
35
|
+
# Default to a help menu if no argument is given.
|
13
36
|
foo = ARGV[0] || ARGV[0] = '-h'
|
14
|
-
|
37
|
+
|
38
|
+
# Parse options into a hash.
|
15
39
|
opts = Trollop::options do
|
16
40
|
banner "whereisthis?".bold.red + " Find out where that ip or website is.".bold
|
17
41
|
version "#{Whereisthis::VERSION}"
|
@@ -25,12 +49,14 @@ module Whereisthis
|
|
25
49
|
opt :ip, "Specify the ip address to lookup", :type => :string
|
26
50
|
opt :website, "Specify the website url to lookup", :type => :string
|
27
51
|
end
|
28
|
-
|
52
|
+
|
53
|
+
# If an ip is specified with -i or --ip at the command-line.
|
29
54
|
if opts.ip
|
30
55
|
unless IPAddress.valid? opts.ip
|
31
56
|
puts "Unable to verify '#{opts.ip}' is a valid ip address."
|
32
57
|
exit 1
|
33
58
|
end
|
59
|
+
# If an website is specified with -w or --website at the command-line.
|
34
60
|
elsif opts.website
|
35
61
|
begin
|
36
62
|
opts[:ip] = IPSocket::getaddress(opts.website)
|
@@ -38,6 +64,7 @@ module Whereisthis
|
|
38
64
|
puts "Unable to resolve #{opts.website} to an ip address. Is it legit?"
|
39
65
|
exit 1
|
40
66
|
end
|
67
|
+
# If the first argument is simply an IP address or website.
|
41
68
|
elsif ARGV[0]
|
42
69
|
if IPAddress.valid? ARGV[0]
|
43
70
|
opts[:ip] = ARGV[0]
|
@@ -51,17 +78,13 @@ module Whereisthis
|
|
51
78
|
end
|
52
79
|
end
|
53
80
|
|
54
|
-
|
55
|
-
puts "Need to specify an ip address or website to figure out what it is!"
|
56
|
-
exit 1
|
57
|
-
end
|
58
|
-
|
81
|
+
# A container of data for our information.
|
59
82
|
Struct.new("WhereIsInfo", :ip, :hostname, :city, :region, :country, :gps, :org, :postal )
|
60
83
|
|
61
84
|
# Get response from web service.
|
62
85
|
data = Unirest.get('http://ipinfo.io/' + opts.ip).body
|
63
86
|
# Change empty values to false.
|
64
|
-
data.each { |k,v| v.empty? ? data[k] = false : data[k] = v }
|
87
|
+
data.each { |k,v| v.nil? || v.empty? ? data[k] = false : data[k] = v }
|
65
88
|
|
66
89
|
whereisinfo = Struct::WhereIsInfo.new
|
67
90
|
|
@@ -75,12 +98,13 @@ module Whereisthis
|
|
75
98
|
whereisinfo.org = data["org"] || "Not found."
|
76
99
|
whereisinfo.postal = data["postal"] || "Not found."
|
77
100
|
|
78
|
-
#
|
101
|
+
# Keep track of the filters & delete the given givens,
|
102
|
+
# because we don't need to keep track of them.
|
79
103
|
filter = Hash[opts.keys.keep_if { |k| k.to_s =~ /_given\b/ } .collect { |i| [i, true] } ]
|
80
104
|
filter.delete_if { |k,v| k.to_s == "ip_given" }
|
81
105
|
filter.delete_if { |k,v| k.to_s == "website_given" }
|
82
106
|
|
83
|
-
#
|
107
|
+
# Manage output with or without filters/ fancy spaces.
|
84
108
|
if filter.count > 0
|
85
109
|
puts "ip: " + whereisinfo.ip if filter[:ip_given]
|
86
110
|
puts "hostname: " + whereisinfo.hostname if filter[:hostname_given]
|
@@ -101,7 +125,6 @@ module Whereisthis
|
|
101
125
|
puts " org: " + whereisinfo.org
|
102
126
|
puts " postal: " + whereisinfo.postal
|
103
127
|
end
|
104
|
-
|
105
128
|
end
|
106
129
|
|
107
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whereisthis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kent Gruber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ipaddress
|