Skip to content

Instantly share code, notes, and snippets.

@BrentonEarl
Last active July 12, 2016 15:33
Show Gist options
  • Save BrentonEarl/31d5968821fad94b0fab05bf9ce61ba8 to your computer and use it in GitHub Desktop.
Save BrentonEarl/31d5968821fad94b0fab05bf9ce61ba8 to your computer and use it in GitHub Desktop.
Makes use of ruby nokogiri to get your public ip by scrapingf duckduckgo.com. Writes results to /tmp and prints it out.
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open("https://duckduckgo.com/html/?q=what%20is%20my%20ip", proxy: ""))
@text = page.css('div#zero_click_abstract')[0].text.strip
open('/tmp/whatismyip', 'w') do |f|
f.puts @text
end
puts @text
@BrentonEarl
Copy link
Author

BrentonEarl commented Jul 11, 2016

Output

$ whatismyip.rb
Your IP address is 111.222.333.444 in Some City, Some State, United States (zipcode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment