whatismyip 1.0.0 → 1.0.1
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.
- data/VERSION +1 -1
- data/lib/whatismyip.rb +22 -9
- data/whatismyip.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/whatismyip.rb
CHANGED
@@ -3,34 +3,47 @@ require 'nokogiri'
|
|
3
3
|
|
4
4
|
class Whatismyip
|
5
5
|
|
6
|
+
attr_reader :public_ip
|
7
|
+
|
6
8
|
def self.check
|
7
9
|
%{
|
8
10
|
Public IP:
|
9
11
|
==========
|
10
|
-
#{
|
12
|
+
#{public_ip}
|
11
13
|
|
12
14
|
Local IP's:
|
13
15
|
===========
|
14
|
-
#{
|
16
|
+
#{display_locals}
|
15
17
|
}.map {|l| (l.strip.empty?) ? l : l.lstrip }
|
16
18
|
end
|
17
19
|
|
18
|
-
def self.
|
19
|
-
|
20
|
-
|
20
|
+
def self.public_ip
|
21
|
+
return @public_ip unless @public_ip.nil?
|
22
|
+
|
23
|
+
begin
|
24
|
+
doc = Nokogiri::HTML(open('http://whatismyip.com/automation/n09230945.asp', 'User-Agent' => "Ruby/#{RUBY_VERSION}"))
|
25
|
+
@public_ip = doc.css('p').inner_html
|
26
|
+
rescue SocketError => e
|
27
|
+
puts "Unable to connect to remote server. Are you sure you're connected to the internet? If not, connect and try again."
|
28
|
+
nil
|
29
|
+
end
|
21
30
|
end
|
22
31
|
|
23
|
-
def self.
|
32
|
+
def self.local_ips
|
24
33
|
result = `ifconfig`
|
25
34
|
|
26
35
|
sections = result.split(/^(?=[^\t])/)
|
27
36
|
sections_with_relevant_ip = sections.select{ |i| i =~ /inet/ }
|
28
37
|
|
29
|
-
sections_with_relevant_ip.
|
38
|
+
Hash[sections_with_relevant_ip.collect { |section|
|
30
39
|
device = section[/[^:]+/]
|
31
40
|
ip = section[/inet ([^ ]+)/, 1]
|
32
|
-
|
33
|
-
}
|
41
|
+
[device.to_sym, ip]
|
42
|
+
}]
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.display_locals
|
46
|
+
local_ips.map { |device, ip| "#{device}: #{ip}\n" }
|
34
47
|
end
|
35
48
|
|
36
49
|
end
|
data/whatismyip.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{whatismyip}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jimmy Baker"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-15}
|
13
13
|
s.default_executable = %q{whatismyip}
|
14
14
|
s.description = %q{Lets you check your public and local ip addresses by simply typing 'whatismyip' on the command-line}
|
15
15
|
s.email = %q{jimmybaker@me.com}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whatismyip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Baker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-15 00:00:00 -06:00
|
13
13
|
default_executable: whatismyip
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|