Skip to content

Instantly share code, notes, and snippets.

@xanthalas
Created September 26, 2012 21:05
Show Gist options
  • Select an option

  • Save xanthalas/3790587 to your computer and use it in GitHub Desktop.

Select an option

Save xanthalas/3790587 to your computer and use it in GitHub Desktop.
Ruby script to retrieve external ip and upload details of it to an FTP server
#!/usr/bin/ruby
require 'net/ftp'
#Retrieve the external IP address, display it to the console and upload it to a web site
ip = `curl --silent --get http://automation.whatismyip.com/n09230945.asp`
print "IP Address: #{ip}\n\n"
time = Time.new
File.open('current_ip', 'w') do |outfile|
outfile.puts "IP Address: #{ip}\n"
outfile.puts "Retrieved on #{time.day}/#{time.month}/#{time.year} at #{time.hour}:#{time.min}
end
FTP_ADDRESS = "<ftp site url goes here>"
FTP_USERNAME = "<ftp username>"
FTP_PASSWORD = "<ftp password>"
FTP_DIRECTORY = "<directory to change to for uploading file>"
Net::FTP.open(FTP_ADDRESS, FTP_USERNAME, FTP_PASSWORD) do |ftp|
ftp.chdir(FTP_DIRECTORY)
ftp.put("current_ip", "current_ip")
end
#You can schedule this to run at regular intervals using cron as follows:
# crontab -e
# Add the following line at the bottom to run it every day at 06:00 and 12:00
# 00 06,12 * * * /home/<user>/getip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment