Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 52 lines (46 sloc) 0.981 kB
f48a939 New Import
Greg Fitzgerald authored
1 #!/usr/bin/env ruby
2 #== Synopsis
3 #
4 # getexternalIP: Fetches your external IP from ipchicken.com, used for boxes behind a firewall.
5 #
6 # = Usage
7 #
8 # getexternalIP [OPTION] ...
9 # -h --help
10 # show this.
11 #
12 # -c --conky
13 # Display just the ip to stdout, used for conky.
14 #
15 # Running with no options will copy your external IP to the clipboard.
16 #
17
18 require 'getoptlong'
19 require 'rdoc/usage'
20
21 def grab_address
22 string = %w[]
23 require 'open-uri'
24 open("http://www.ipchicken.com/") { |fm|
25 string = fm.read
26 @myip = string.scan(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/).join("\n")
27 }
28 return @myip
29 end
30
31 opts = GetoptLong.new(
32 [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
33 [ '--conky', '-c', GetoptLong::NO_ARGUMENT ]
34 )
35
36 opts.each do |opt, arg|
37 case opt
38 when '--help'
39 RDoc::usage
40 exit 1
41 when '--conky'
42 puts grab_address
43 exit 1
44 end
45 end
46
47 if ARGV.empty?
48 addy = grab_address
49 system("echo #{addy} | xclip")
50 exit 1
51 end
Something went wrong with that request. Please try again.