#coding: utf-8
import string
import urllib
from ftplib import FTP
#get ip from the website
page = urllib.urlopen('http://www.whereismyip.com')
while 1:
line = page.readline()
if line:
if line.find('<b><font color="#000000" size="10" face="verdana">') != -1:
line = line.split('face="verdana">')
line = line[1].split('</font></b>')
ip = line[0]
else:
break
#write to the file
file_name = 'ip.txt'
file = open(file_name,'w')
file.write(ip)
file.close()
#upload the file
ftp=FTP()
#ftp.set_debuglevel(2)
ftp.connect('ftp.xxxx.com.cn','21')
ftp.login('xxxx','xxxx')
#print ftp.getwelcome()
)
bufsize = 1024
filename='ip.txt'
file_handler = open(filename,'rb')
ftp.storbinary('STOR ip.txt',file_handler,bufsize)
#ftp.set_debuglevel(0)
file_handler.close()
ftp.quit()