dumper 0.0.1 → 0.0.2

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.
@@ -1,29 +1,9 @@
1
- require 'dumper/version'
2
1
  require 'thor'
3
2
  require 'rainbow'
4
3
  require 'socket'
5
4
 
6
5
  module Dumper
7
- autoload :Cli, 'dumper/cli'
8
- end
9
-
10
- require 'ipaddr'
11
- class IPAddr
12
- PrivateRanges = [
13
- IPAddr.new("10.0.0.0/8"),
14
- IPAddr.new("172.16.0.0/12"),
15
- IPAddr.new("192.168.0.0/16")
16
- ]
17
-
18
- def private?
19
- return false unless self.ipv4?
20
- PrivateRanges.each do |ipr|
21
- return true if ipr.include?(self)
22
- end
23
- return false
24
- end
25
-
26
- def public?
27
- !private?
28
- end
6
+ autoload :Cli, 'dumper/cli'
7
+ autoload :Utility, 'dumper/utility'
8
+ autoload :VERSION, 'dumper/version'
29
9
  end
@@ -11,14 +11,14 @@ module Dumper
11
11
  no_tasks do
12
12
  def check_ip
13
13
  puts 'Checking IP address...'
14
- ip = IPSocket.getaddress(Socket.gethostname)
15
- ip_str = "#{ip} ... "
16
- if IPAddr.new(ip).private?
17
- ip_str << 'private'.color(:red)
14
+ @ip = Dumper::Utility::IP.new
15
+ str = "#{@ip.ip} ... "
16
+ if @ip.ipaddr.private?
17
+ str << 'private'.color(:red)
18
18
  else
19
- ip_str << 'public'.color(:green)
19
+ str << 'public'.color(:green)
20
20
  end
21
- puts ip_str
21
+ puts str
22
22
  end
23
23
 
24
24
  def check_cnf
@@ -0,0 +1,39 @@
1
+ require 'ipaddr'
2
+
3
+ module Dumper
4
+ module Utility
5
+ class IP
6
+ attr_reader :ip, :ipaddr
7
+
8
+ def initialize(*args)
9
+ disable_reverse_lookup do
10
+ UDPSocket.open do |s|
11
+ s.connect '64.233.187.99', 1
12
+ @ip = s.addr.last
13
+ end
14
+ end
15
+ @ipaddr = Dumper::Utility::IPAddr.new(@ip)
16
+ end
17
+
18
+ def disable_reverse_lookup
19
+ orig = Socket.do_not_reverse_lookup
20
+ Socket.do_not_reverse_lookup = true
21
+ begin
22
+ yield
23
+ ensure
24
+ Socket.do_not_reverse_lookup = orig
25
+ end
26
+ end
27
+ end
28
+
29
+ class IPAddr < ::IPAddr
30
+ def private?
31
+ return false unless self.ipv4?
32
+
33
+ [ IPAddr.new("10.0.0.0/8"),
34
+ IPAddr.new("172.16.0.0/12"),
35
+ IPAddr.new("192.168.0.0/16") ].any?{|i| i.include? self }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Dumper
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-28 00:00:00.000000000 Z
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -60,6 +60,7 @@ files:
60
60
  - dumper.gemspec
61
61
  - lib/dumper.rb
62
62
  - lib/dumper/cli.rb
63
+ - lib/dumper/utility.rb
63
64
  - lib/dumper/version.rb
64
65
  homepage: ''
65
66
  licenses: []