netgeo 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 570b73ac609c08dd02afcacbf2583d56177cfd63
4
+ data.tar.gz: ff37a1367636d75a1b440e2401cda7f24ae74cfa
5
+ SHA512:
6
+ metadata.gz: adee6a17384f533d26eda8dce4177188e8d15c190e1d05b2e961306ed7eb434a5d57cd4f4c9c5465f9d76bfe74b6939b67d35d4de66490b720da69f7eda12f9e
7
+ data.tar.gz: 7700714e87c33551465963301b50b246900b04eb4187ea04a3a625491af1e3effb0ee5945a75b2d032101b1bf087005a8b1c6570a218a49a8111d22cc85dc2c3
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in netgeo.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ # Netgeo
2
+
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/netgeo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'netgeo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install netgeo
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jakewmeyer/netgeo.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "netgeo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # Simple CLI app for basic network information
5
+ # with options for nice output or simple stdout
6
+ # to make all your piping dreams come true.
7
+ #
8
+
9
+
10
+ require 'slop'
11
+ require 'rest-client'
12
+ require 'json'
13
+ require 'os'
14
+ require 'socket'
15
+
16
+
17
+ # Contains option parsing logic
18
+ def netgeo
19
+ opts = Slop.parse suppress_errors: true do |o|
20
+ o.banner = 'Usage: netgeo [flag]'
21
+
22
+ # Gets WAN address
23
+ o.on '-w', '--wan', 'Returns WAN IP' do
24
+ url = "https://api.ipify.org"
25
+ response = RestClient.get(url)
26
+ puts response
27
+ end
28
+
29
+ # Gets LAN(s)
30
+ o.on '-l', '--lan', 'Returns LAN IP(s)' do
31
+ lans = Socket.ip_address_list.select{|intf| intf.ipv4_private?}.map { |intf| intf.ip_address }
32
+ puts lans.join(', ')
33
+ end
34
+
35
+ # Gets Router IP
36
+ o.on '-r', '--router', 'Returns Router IP' do
37
+ if OS.linux?
38
+ router = %x[ip route | grep default | head -1 | awk '{print$3}']
39
+ elsif OS.mac?
40
+ router = %x[netstat -rn | grep default | head -1 | awk '{print$2}']
41
+ else
42
+ puts "OS not supported!"
43
+ exit(1)
44
+ end
45
+ puts router
46
+ end
47
+
48
+ # Gets DNS nameserver
49
+ o.on '-d', '--dns', 'Returns DNS Nameserver' do
50
+ if OS.linux?
51
+ dns = %x[cat /etc/resolv.conf | grep nameserver | head -1 | awk '{print$2}']
52
+ elsif OS.mac?
53
+ dns = %x[scutil --dns | grep nameserver | head -1 | awk '{print$3}']
54
+ else
55
+ puts "OS not supported!"
56
+ exit(1)
57
+ end
58
+ puts dns
59
+ end
60
+
61
+ o.string '-m', '--mac [interface]', 'Returns MAC address for interface. Ex. eth0'
62
+
63
+
64
+ o.on '-g', '--geo', 'Returns Current IP Geodata' do
65
+ url = "http://ip-api.com/json/"
66
+ response = RestClient.get(url)
67
+ info = JSON.parse(response)
68
+ puts info['query']
69
+ puts info['city']
70
+ puts info['region']
71
+ puts info['country']
72
+ puts info['zip']
73
+ puts info['isp']
74
+ end
75
+ o.separator ''
76
+ o.separator 'Custom Geo Output:'
77
+ o.separator '[all] [ip] [city] [region] [country] [zip] [isp]'
78
+ o.separator 'Example: netgeo -s ip,city,isp 8.8.8.8'
79
+ o.array '-s', '[options] [ip address]', 'Specific Geodata'
80
+ o.on '-h', '--help', 'version 1.0.2' do
81
+ puts o
82
+ exit
83
+ end
84
+ end
85
+
86
+
87
+ # Logic for specific geodata
88
+ options = opts[:s]
89
+ ip = opts.arguments || ''
90
+
91
+ url = "http://ip-api.com/json/#{ip.join}"
92
+ response = RestClient.get(url)
93
+ info = JSON.parse(response)
94
+ if options.include? 'all'
95
+ puts info['query']
96
+ puts info['city']
97
+ puts info['region']
98
+ puts info['country']
99
+ puts info['zip']
100
+ puts info['isp']
101
+ else
102
+ puts info['query'] if options.include? 'ip'
103
+ puts info['city'] if options.include? 'city'
104
+ puts info['region'] if options.include? 'region'
105
+ puts info['country'] if options.include? 'country'
106
+ puts info['zip'] if options.include? 'zip'
107
+ puts info['isp'] if options.include? 'isp'
108
+ end
109
+
110
+
111
+ # Logic for specific MAC address
112
+ options = opts[:m]
113
+ unless options == nil
114
+ puts %x[ifconfig #{options} | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}']
115
+ end
116
+ end
117
+
118
+ netgeo
@@ -0,0 +1,5 @@
1
+ require "netgeo/version"
2
+
3
+ module Netgeo
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Netgeo
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "netgeo/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "netgeo"
8
+ spec.version = Netgeo::VERSION
9
+ spec.authors = ["Jake Meyer"]
10
+ spec.email = ["jakewmeyer@gmail.com"]
11
+
12
+ spec.summary = %q{A CLI tool for ip, dns, mac, and geolocation data, with clean output for piping}
13
+ spec.homepage = "https://github.com/jakewmeyer/Ruby-Scripts"
14
+
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "os"
27
+ spec.add_development_dependency "slop"
28
+ spec.add_development_dependency "rest-client"
29
+
30
+ spec.add_runtime_dependency "os"
31
+ spec.add_runtime_dependency "slop"
32
+ spec.add_runtime_dependency "rest-client"
33
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netgeo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jake Meyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: os
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: slop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: os
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: slop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rest-client
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - jakewmeyer@gmail.com
142
+ executables:
143
+ - netgeo
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - README.md
152
+ - Rakefile
153
+ - bin/console
154
+ - bin/setup
155
+ - exe/netgeo
156
+ - lib/netgeo.rb
157
+ - lib/netgeo/version.rb
158
+ - netgeo.gemspec
159
+ homepage: https://github.com/jakewmeyer/Ruby-Scripts
160
+ licenses: []
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.6.12
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: A CLI tool for ip, dns, mac, and geolocation data, with clean output for
182
+ piping
183
+ test_files: []