Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.lang.python > #7620
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Max_Adamo <maxadamo@usenet.cnntp.org> |
| Newsgroups | it.comp.lang.python |
| Subject | Re: ip Pubblico |
| Date | Sat, 19 Mar 2016 16:56:22 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 85 |
| Message-ID | <nck0bm$o1t$2@dont-email.me> (permalink) |
| References | <jfPGy.42660$pt.19549@tornado.fastwebnet.it> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Sat, 19 Mar 2016 16:56:22 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="def1a60fa1fd3e6d9dd9b3c31de5190b"; logging-data="24637"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196rWvHh5exALx7fexsm5Fjy04DdPXQpsQ=" |
| User-Agent | Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) |
| X-Face | /home/maxadamo/.signature/X-Face |
| Cancel-Lock | sha1:npPuGUrjZMED8V+FNsdjN80rTos= |
| Xref | csiph.com it.comp.lang.python:7620 |
Show key headers only | View raw
Il Fri, 18 Mar 2016 09:46:07 +0100, Smith ha scritto:
> Ciao a tutti,
> ho questo script e vorrei suddividerlo in funzioni per renderlo più
> sintetico possibile.
> Mi potete aiutare?
> Grazie
>
sicuramente contiene errori (non l'ho provato!)... o potrebbe anche essere
una cavolata che non funziona...
#!/usr/bin/python3
"""
Script per verificare l'IP pubblico
"""
import urllib.request
import smtplib
import time
# Tempo di attesa in secondi tra due controlli
attesa = 600
# Parametri per invio email
destinatario = "email_destinataio@gmail.com"
mittente = 'email_mittente@gmail.com'
username = 'email_mittente@gmail.com'
password = 'password'
# Altre variabili
MemoriaIp = ""
conta = 0
def invia_email(username, password, mittente, destinatario, msg, attesa):
""" Invia email """
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.ehlo()
server.login(username,password)
server.sendmail(mittente, destinatario, msg)
server.quit()
time.sleep(attesa)
def controlla_ip():
while True:
conta += 1
print("**********************************")
print("Controllo n. %i" % conta)
# Legge IP pubblico
socks = urllib.request.urlopen("http://ipecho.net/plain")
ReadIP = socks.read()
socks.close()
ReadIp.decode("utf-8")
print("Indirizzo ip assegnato :",MemoriaIp)
if ReadIP != MemoriaIp:
# Comunica nuovo IP a video
print("Rilevato nuovo IP %s" % ReadIP)
elif ReadIP == MemoriaIp:
break
# Ricorda IP per verifica cambiamento
return ReadIP
if __name__ == '__main__':
while True or False:
MemoriaIp = controlla_ip()
# Prepara variabili per email
oggetto = 'Notifica IP %s' % ReadIP
testo = 'Il tuo IP: %s' % ReadIP
header = 'From: %s\n' % mittente
header += 'To: %s\n' % destinatario
header += 'Subject: %s\n\n' % oggetto
msg = header + testo
invia_email(username, password, mittente, destinatario, msg,
attesa)
--
Massimiliano Adamo
Back to it.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
ip Pubblico Smith <smith@a-team.it> - 2016-03-18 09:46 +0100
Re: ip Pubblico Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-03-19 16:56 +0000
Re: ip Pubblico Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-03-19 20:35 +0000
Re: ip Pubblico Claudio_F <clau.fin@tin.it> - 2016-03-19 21:12 +0100
Re: ip Pubblico Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-03-19 20:44 +0000
Re: ip Pubblico Claudio_F <clau.fin@tin.it> - 2016-03-19 22:32 +0100
Re: ip Pubblico Smith <smith@a-team.it> - 2016-03-22 09:17 +0100
csiph-web