Skip to content

Instantly share code, notes, and snippets.

@PHLAK
Created February 14, 2011 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PHLAK/826108 to your computer and use it in GitHub Desktop.
Save PHLAK/826108 to your computer and use it in GitHub Desktop.
Connects to whatismyip.com, obtains your external IP address and uploads a text file containg the IP to a chosen FTP server. Requires Python to run.
#! /usr/bin/env python
import httplib
import sys
import os
import ftplib
# File IP will be output to
file="ip.txt"
# Replace server, user, and password with your login information
server = "http://server.com"
user = "username"
password = "password"
conn = httplib.HTTPConnection("www.whatismyip.com")
conn.request("GET","/automation/n09230945.asp")
response = conn.getresponse()
data = response.read()
filename = str(os.path.abspath(os.path.dirname(sys.argv[0])) + "\\"+file) #Create file
FILE = open(filename,"w") #Open file ready for writing
FILE.writelines(data) #Write 'data' to file
FILE.close() #Close file
s = ftplib.FTP(server,user,password) #Connect
f = open(file,'rb') #File to send
s.storbinary('STOR '+file, f) #Send the file
f.close() #Close file and FTP
s.quit() #Quit FTP
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment