Skip to content

Instantly share code, notes, and snippets.

@bradland
Last active Dec 27, 2015
Embed
What would you like to do?
Tells you your IP address and a xip.io address to the same for common Ruby app server ports
#!/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