feedback wilkommen
Code: Alles auswählen
#!/usr/bin/env python
#name:ip2domain.py
#date: Mar 24 2007
#description: warrant that a file containing a html redirect to your (dynamic) ip is mantained via ftp
import urllib
import getpass
import ftplib
from time import sleep
class DummyFile(object):
def __init__(self, str):
self.str = str.splitlines()
self.str.reverse()
def readline(self):
if not self.str:
return ''
return self.str.pop()
host = raw_input('domain: ')
user = raw_input('login: ')
pwd = getpass.getpass()
file = raw_input('file: ')
port = raw_input('redirect port (default 80): ')
if not port:
port = '80'
if '/' in file:
z = file.split('/')
path = '/'.join(z[0:-1])
file = z[-1]
print path, file
else:
path = None
my_ip_prev = ''
erste_runde = True
while True:
print 'refreshing'
my_ip = urllib.urlopen('http://checkip.dyndns.org/').read()[76:-16]
if my_ip != my_ip_prev:
print 'your ip:', my_ip
f = ftplib.FTP(host)
f.login(user, pwd)
if path:
f.cwd(path)
if not erste_runde:
f.delete(file)
f.storlines('STOR ' + file, DummyFile("""<html>
<head>
<title>redirecting...</title>
<meta http-equiv="REFRESH" content="0;url=http://%s:%s">
</head>
<BODY>
<a href=http://%s:%s>click here</a>
</BODY>
</HTML>""" % (my_ip, port, my_ip, port)
))
f.close()
my_ip_prev = my_ip
erste_runde = False
sleep(60 * 10)