Skip to content

Instantly share code, notes, and snippets.

Last active Dec 27, 2015
What would you like to do?
Tells you your IP address and a 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 = ''
# "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}"
puts "http://#{app_name}#{public_ip}"
puts "http://#{app_name}#{public_ip}"
# Fetch a page from the internets, return the contents
def get_page(url)
# 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','*')]! do |powfile|
File.realdirpath(powfile) == pwd
powfiles.first ? File.basename(powfiles.first) : nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment