Skip to content

Instantly share code, notes, and snippets.

@Demeter
Forked from PHLAK/ip-uploader.py
Created September 18, 2011 05:16
Show Gist options
  • Save Demeter/1224758 to your computer and use it in GitHub Desktop.
Save Demeter/1224758 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