Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: clean
Fetching contributors…

Cannot retrieve contributors at this time

executable file 52 lines (46 sloc) 0.981 kB
#!/usr/bin/env ruby
#== Synopsis
#
# getexternalIP: Fetches your external IP from ipchicken.com, used for boxes behind a firewall.
#
# = Usage
#
# getexternalIP [OPTION] ...
# -h --help
# show this.
#
# -c --conky
# Display just the ip to stdout, used for conky.
#
# Running with no options will copy your external IP to the clipboard.
#
require 'getoptlong'
require 'rdoc/usage'
def grab_address
string = %w[]
require 'open-uri'
open("http://www.ipchicken.com/") { |fm|
string = fm.read
@myip = string.scan(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/).join("\n")
}
return @myip
end
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--conky', '-c', GetoptLong::NO_ARGUMENT ]
)
opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage
exit 1
when '--conky'
puts grab_address
exit 1
end
end
if ARGV.empty?
addy = grab_address
system("echo #{addy} | xclip")
exit 1
end
Jump to Line
Something went wrong with that request. Please try again.