Skip to content

Instantly share code, notes, and snippets.

@struct
Created April 23, 2011 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save struct/938180 to your computer and use it in GitHub Desktop.
Save struct/938180 to your computer and use it in GitHub Desktop.
dropbox IP scraper
## Disclaimer: This script sucks. It is a simple page
## scraper I wrote in about 10 minutes. Dropbox has no
## API calls for checking what IP addresses have accessed
## your Dropbox. When they change their website this
## script won't work anymore. It also requires curb
## which you can install with rubygems
## @chrisrohlf
require 'rubygems'
require 'curb'
DROPBOX_USERNAME = 'YOUR_EMAIL' ## Your email address (Dropbox login)
DROPBOX_PASSWORD = 'YOUR_PASSWORD' ## Your password here
TRUSTED_IPS = %w[ 1.1.1.1 ] ## Trusted IPs that may access your account
TRUSTED_HOSTS = %w[ mymachine1 machine2 ] ## Trusted machine names, make sure no one added one
MINUTES = 1 ## How often should I check
puts "you didnt actually look at the script did you? Go back and fill it out."
exit
class DropboxIPChecker
attr_accessor :curl, :cookies
def initialize
@curl = Curl::Easy.http_post('https://www.dropbox.com/login',
Curl::PostField.content('login_email', DROPBOX_USERNAME),
Curl::PostField.content('login_password', DROPBOX_PASSWORD))
@cookies = String.new
curl.on_header do |header|
if header =~ /set-cookie/
hdr,cookie = header.split(':')
k,v = cookie.split('=')
v = v.gsub!('Domain', '') if v =~ /Domain/
v = v.split(';').first
cookies << "#{k}=#{v};"
end
header.length
end
curl.perform
end
def get_page
curl.on_header
curl = Curl::Easy.new('https://www.dropbox.com/account')
curl.cookies = @cookies
curl.perform
curl.body_str
end
def get_ips
ips = []
page = get_page
page.each_line { |s| ips << s.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/).to_s if s.match(/Tooltip/) }
ips.uniq
end
def get_hosts
hosts = []
page = get_page
page.each do |h|
if h.match(/Hosts.edit\(\'[0-9]{0,4}/) && h.match(/ondblclick/)
a = h.match(/>[a-zA-Z0-9\-]{1,256}[^<]/).to_s.gsub!('>', '').to_s
hosts << a
end
hosts << 'iPhone' if h.match(/class=\"sprite s_iphone_small\"/)
end
hosts.uniq
end
def stay_vigilant
while 1
ips = get_ips
hosts = get_hosts
ips.each { |ip| yield ip if !TRUSTED_IPS.include?(ip) }
hosts.each { |h| yield h if !TRUSTED_HOSTS.include?(h) }
sleep(MINUTES * 60)
end
end
end
WINDOWS_OS = /win(dows|32)|i386-mingw32/i
LINUX_OS = /linux/i
OSX_OS = /darwin/i
db = DropboxIPChecker.new
db.stay_vigilant do |u|
case
when RUBY_PLATFORM =~ LINUX_OS
puts "Unauthorized Dropbox Use! #{u}"
when RUBY_PLATFORM =~ WINDOWS_OS
puts "Unauthorized Dropbox Use! #{u}"
when RUBY_PLATFORM =~ OSX_OS
`/usr/local/bin/growlnotify 'Unauthorized Dropbox Use!' -a Safari -m '#{u}'` ## -s for sticky
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment