Last active
December 27, 2015 14:59
-
-
Save bradland/7344626 to your computer and use it in GitHub Desktop.
Tells you your IP address and a xip.io address to the same for common Ruby app server ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'uri' | |
require 'fileutils' | |
class App | |
# The website configured for this constant should serve text/plain with | |
# nothing but the IP address. Feel free to substitute your own. | |
IP_URL = 'http://wtfismyip.com/text' | |
# "Main" application method; this runs on script execute | |
def run | |
public_ip = get_page(IP_URL).chomp | |
app_name = pow_name ? "#{pow_name}." : nil | |
puts "Public IP:" | |
puts public_ip | |
puts "" | |
puts "App server URLs (click thrice to select):" | |
puts "http://#{app_name}#{public_ip}.xip.io" | |
puts "http://#{app_name}#{public_ip}.xip.io:3000" | |
puts "http://#{app_name}#{public_ip}.xip.io:4567" | |
end | |
# Fetch a page from the internets, return the contents | |
def get_page(url) | |
Net::HTTP.get(URI.parse(url)) | |
end | |
# Returns the name of the pow app or nil if none are found | |
def pow_name | |
pwd = Dir.pwd | |
powfiles = Dir[File.join(ENV['HOME'], '.pow','*')] | |
powfiles.select! do |powfile| | |
File.realdirpath(powfile) == pwd | |
end | |
powfiles.first ? File.basename(powfiles.first) : nil | |
end | |
end | |
App.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment